Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hosting RemoteAPP session within Winform

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.

like image 497
Nabbic Avatar asked May 30 '13 13:05

Nabbic


1 Answers

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();
like image 161
Mitch Avatar answered Oct 24 '22 20:10

Mitch