1

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.

FrameWorker
  • 11
  • 1
  • 2
  • Try to change code to this: `((ITSRemoteProgram)((IMsRdpClient7)rdp.GetOcx()).RemoteProgram2).ServerStartProgram(@"%SYSTEMROOT%\calc.exe", "", @"%SYSTEMROOT%", true, "", false );` – Alezis Oct 10 '13 at 09:44
  • Thanks for the rapid answer, but this didn't work. It still brings me a whole black screen. – FrameWorker Oct 10 '13 at 10:19
  • Mea culpa! It works perfect if, and only if: a) the target pc is Windows Server ( I finally tested it on Windows Server 2008 R2) and b) you declare the app you want to launch in the RemoteApp Manager's Programs List. – FrameWorker Oct 11 '13 at 13:28

2 Answers2

1

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.

Misch
  • 8,600
  • 4
  • 33
  • 48
flyingdirt
  • 11
  • 2
0

Comment out this line and it will work perfectly.

// client.RemoteProgram2.RemoteProgramMode = true;
Ralph Willgoss
  • 9,622
  • 4
  • 64
  • 65
Burak Dincer
  • 65
  • 1
  • 9