我已经使用了多年的C#应用程序来编写远程桌面连接的脚本。它总是建立在AxMsRdpClient3上(注意3,我猜它是某种版本号)。我希望能够使用AxMsRdpClient8 (version 8)中的一些特性,但据我所知,这需要安装远程桌面版本8。但是,并不是所有的用户都已经安装了它(甚至可以在Windows /Vista上安装它)。
因此,正如盛江所建议的,我现在正在运行时创建控件,并且我有如下代码:
try
{
AxMsRdpClient8 rdp8 = new AxMsRdpClient8();
rdp8.BeginInit();
// set some properties here
rdp8.EndInit(); // throws Exception on machines without version 8 installed
}
catch (Exception ex)
{
AxMsRdpClient3 rdp3 = new AxMsRdpClient3();
rdp3.BeginInit();
// set some properties here
rdp3.EndInit();
}
正如预期的那样,rdp8.EndInit()在没有安装远程桌面版本8的计算机上抛出一个异常。问题是,在尝试创建AxMSRDPClient8之后,rdp3.EndInit()在旧机器上也会失败(类未注册)。如果我不首先尝试创建AxMSRDPClient8,则AxMSRDPClient3将初始化并正确工作。
发布于 2014-02-27 02:22:00
每个版本的RDP activeX都有一个不同的clsid。。您需要检测OS版本并创建运行时具有与您计划支持的最低OS版本对应的类id的activex。。
如果您的代码依赖于后期绑定,那么最好重写代码以使用IMsRdpClient*和IMsRdpClientNonScriptable*。例如,MsRdpClient8NotSafeForScripting支持以下接口:
MsRdpClient3NotSafeForScripting支持
如果要检测activex是否支持特定的接口版本,只需将ActiveX的实例转换为接口即可。当转换失败时,您知道接口不受支持。
protected void CreateRdpActiveX()
{
try
{
string clsid=GetRdpActiveXClsIdByOSVersion();
Type type = Type.GetTypeFromCLSID(clsid, true);
this.axRdp = new AxHost (type.GUID.ToString());
((ISupportInitialize)(axRdp)).BeginInit();
SuspendLayout();
this.panel1.Controls.Add(axRdp);
((ISupportInitialize)(axRdp)).EndInit();
ResumeLayout(false);
var msRdpClient8 = axRdp.GetOcx() as IMsRdpClient8;
if(msRdpClient8!=null)
{
var advancedSettings9 =msRdpClient8.AdvancedSettings9 as IMsRdpClientAdvancedSettings8;
if(advancedSettings9!=null)
advancedSettings9.BandwidthDetection=true;
}
}
catch (System.Exception ex)
{
System.Console.WriteLine(ex.Message);
}
}
https://stackoverflow.com/questions/22049141
复制相似问题