到目前为止,我创建了一个应用程序,使用 AxMsTscAxNotSafeForScripting 类进行远程桌面连接。一切都像魅力一样!现在,我需要配置此对象以在连接时启动特定应用程序。
让我们看看代码
AxMsTscAxNotSafeForScripting rpd = new AxMsTscAxNotSafeForScripting();
var client = (IMsRdpClient7)rdp.GetOcx();
client.RemoteProgram2.RemoteProgramMode = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).DisplayConnectionBar = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).ConnectionBarShowPinButton = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).BitmapVirtualCache32BppSize = 48;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).ConnectionBarShowRestoreButton = false;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).ConnectionBarShowMinimizeButton = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).EnableWindowsKey = 1;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).GrabFocusOnConnect = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).RedirectDrives = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).RedirectClipboard = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).RedirectPrinters = true;
((MSTSCLib.IMsRdpClientAdvancedSettings5)rdp.AdvancedSettings).RedirectPOSDevices = true;
rdp.Server = txtServer.Text;
rdp.UserName = txtUserName.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = txtPassword.Text;
rdp.FullScreenTitle = "Full Screen";
rdp.SecuredSettings.FullScreen = 1;
rdp.SecuredSettings.StartProgram = @"c:\windows\System32\calc.exe";
rdp.Connect();
做完这一切后,我得到的是一个连接的屏幕,但它是一个全黑的屏幕。然后,我注释第三行: //client.RemoteProgram.RemoteProgramMode = true;
这给了我一个连接的屏幕,在正确的计算机上,但没有应用程序出现。
我还尝试了 rdp_OnConnected 事件,添加了这段代码:
((ITSRemoteProgram)((IMsRdpClient7)rdp.GetOcx()).RemoteProgram2).ServerStartProgram(@"c:\windows\System32\calc.exe", null, @"C:\Windows\System32", false, "", false );
但仍然没有发生任何事情。
我很想在这里得到一些帮助。