13

Keep coming back to this and cannot figure it out... I am creating an app for work that essentially compiles all of our tools into one easier to use GUI. One of the tools we use is something we use from a 3rd party and is hosted as a Remote App via RDWeb. Now I also have just regular remote desktop access as well and I can access the desktop via my Winform using MSTSC and this process which works beautifully. I am curious if it is possible to just load the RemoteAPP and not the entire desktop in the MSTSC control so that my users aren't getting to the full desktop. Or if there is any other way to host a RemoteAPP Only within Winforms.

I have reviewed the MSDN documentation on ITSRemoteProgram but when I try the following it just throws an exception.The debugger stops at rdp.RemoteProgram.RemoteProgramMode = true; and gives an HRESULT E_FAIL exception.

I have also tried using the remoteprogram after the OnConnected event fires and I get the same results.

try
{
    rdp.Server = "FFWIN2008R2DC.fflab123.net";
    rdp.Domain = "fflab123";
    rdp.UserName = "administrator";
    IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
    secured.ClearTextPassword = "password123";
    rdp.OnConnected += rdp_OnConnected;
    rdp.RemoteProgram.RemoteProgramMode = true;
    rdp.RemoteProgram2.RemoteApplicationName = "Calculator";
    rdp.RemoteProgram2.RemoteApplicationProgram = @"C:\Windows\system32\calc.exe";

    rdp.Connect();
}
catch (Exception Ex)
{
    MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
}

Perhaps I am going at this the wrong way or perhaps its not even possible. I would just like a nudge in the correct direction I dont need anyone to write this for me.

Vikas Gupta
  • 4,329
  • 1
  • 17
  • 37
Nabbic
  • 417
  • 3
  • 21
  • No one has any information on this? I guess that explains why i can't figure it out either lol. – Nabbic Jun 16 '13 at 08:09

1 Answers1

4

IMsRdpClient.RemoteProgram.RemoteProgramMode is only valid on clients initialized from the MsRdpClientNotSafeForScripting class ids. See this MSDN page for the appropriate CLSIDs, or use the AxMsRdpClientNotSafeForScripting interop class.

var rc = new AxMsRdpClient7NotSafeForScripting();
rc.Dock = DockStyle.Fill;
this.Controls.Add(rc);
rc.RemoteProgram.RemoteProgramMode = true;
// ServerStartProgram can only be called on an open session; wait for connected until calling
rc.OnConnected += (_1, _2) => { rc.RemoteProgram.ServerStartProgram(@"%SYSTEMROOT%\notepad.exe", "", "%SYSTEMROOT%", true, "", false); };
rc.Server = "server.name";
rc.UserName = "domain\\user";
// needed to allow password
rc.AdvancedSettings7.PublicMode = false;
rc.AdvancedSettings7.ClearTextPassword = "password";
// needed to allow dimensions other than the size of the control
rc.DesktopWidth = SystemInformation.VirtualScreen.Width;
rc.DesktopHeight = SystemInformation.VirtualScreen.Height;
rc.AdvancedSettings7.SmartSizing = true;

rc.Connect();
Mitch
  • 19,026
  • 4
  • 57
  • 77
  • Thanks for the response! So i implemented this partially successfully. It get's me a step forward i think but not fully there. Now when i try and connect it at least connects with RemoteProgramMode true and i can see it log in and then as it is going to load notepad for example it just sits on a blue screen and never actually loads the program. I do not get a desktop either just a blue screen like it is going to load the app but still fails. Any ideas? – Nabbic Jun 25 '13 at 21:31
  • @Nabbic, If you don't start an application, or if you attempt to start an application which is not allowed or does not exist, you will end up with the blue desktop visible only. Make sure you are opening the program. You can verify using task manager or another program running on the target server. Additionally, ensure you set the `DesktopWidth` and `DesktopHeight` members, or you are limited to the size of the control as placed on the form. The 5 minute timeout is if there are no applications open on the remote server. – Mitch Jun 26 '13 at 03:19
  • I have the same requirement to implement something similar. The answer almost worked for me. The only difference is that the remote app opens outside of the WinForm. The WinForm opens blank but another window opens the remote app. I want it to open inside the Winform where I have the ActiveX component. What is missing in the code above that would allow this to happen? – Ray Sep 05 '20 at 03:17