[英]How can I create an remote application connection throught .NET?
So far, I created an app, using AxMsTscAxNotSafeForScripting class for Remote Desktop connection. 到目前为止,我已经创建了一个应用程序,使用AxMsTscAxNotSafeForScripting类进行远程桌面连接。 Everything works like a charm!
一切都像一个魅力! Now, what I need is to configure this object to launch a specific application upon connection.
现在,我需要配置此对象以在连接时启动特定的应用程序。
Let's see the code 让我们看一下代码
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();
After doing all this, what I get is a connected screen, but it is a whole black screen. 完成所有这些操作后,我得到的是连接的屏幕,但它是一个全黑屏幕。 Then, I comment the third line: //client.RemoteProgram.RemoteProgramMode = true;
然后,我对第三行进行注释://client.RemoteProgram.RemoteProgramMode = true;
This gives me a connected screen, on the right computer, BUT no application appears. 这给了我一个连接的屏幕,在正确的计算机上,但是没有应用程序出现。
I also tried the rdp_OnConnected event, adding this piece of code: 我还尝试了rdp_OnConnected事件,添加了以下代码:
((ITSRemoteProgram)((IMsRdpClient7)rdp.GetOcx()).RemoteProgram2).ServerStartProgram(@"c:\windows\System32\calc.exe", null, @"C:\Windows\System32", false, "", false );
but still nothing happened. 但仍然没有任何反应。
I 'l love to have some help here. 我很乐意在这里提供帮助。
if your system is win7 or xp, you should change the registry. 如果您的系统是win7或xp,则应更改注册表。 The first step is to activate RemoteApp on Windows 7 by setting the Registry key
HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Terminal Server\\TSAppAllowList: fDisabledAllowList
to the value 1
. 第一步是通过将注册表项
HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Terminal Server\\TSAppAllowList: fDisabledAllowList
设置为值1
来激活Windows 7上的RemoteApp。 if your system is win server 2008, you should use remoteapp manager to add the remoteapp to the allowedlist. 如果您的系统是Win Server 2008,则应使用remoteapp管理器将remoteapp添加到允许列表。 After that, you can use ServerStartProgram function.
之后,您可以使用ServerStartProgram函数。
注释掉此行,它将正常运行。
// client.RemoteProgram2.RemoteProgramMode = true;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.