FrameWorker
FrameWorker

Reputation: 11

How can I create an remote application connection throught .NET?

So far, I created an app, using AxMsTscAxNotSafeForScripting class for Remote Desktop connection. 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;

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:

((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.

Upvotes: 1

Views: 5888

Answers (2)

flyingdirt
flyingdirt

Reputation: 11

if your system is win7 or xp, you should change the registry. 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. if your system is win server 2008, you should use remoteapp manager to add the remoteapp to the allowedlist. After that, you can use ServerStartPro‌​gram function.

Upvotes: 1

Burak Dincer
Burak Dincer

Reputation: 65

Comment out this line and it will work perfectly.

// client.RemoteProgram2.RemoteProgramMode = true;

Upvotes: 0

Related Questions