locked
Hosting Remote Desktop Connection in WPF App RRS feed

  • Question

  • Hello all.

    I am wanting to create a Remote Desktop application in WPF.  My first crack at it was to use the ActiveX control provided by Windows; using these two articles as reference:

    http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/acbbb4ae-5d31-404b-91b8-919493947e7b

    Walkthrough: Hosting an ActiveX Control in WPF

    I've been able to get it to work, but the RDC client shows up as a small box (maybe 200x200 pixels) in the center of the display.  Does anyone know why that might be happening and how I can fix it?  I believe it is on the Forms side, or the ActiveX control itself -- the layout options on the WPF side are all set correctly for your average WPF control.

    Alternatively, is there a better (native) way to do this in WPF?  I've done some searches for an example implementation but have only found articles talking about the ActiveX control, or writing the app to use Windows Forms.

    Thanks for any help!

    • Changed type Evil Closet Monkey Thursday, August 26, 2010 4:59 PM It really is a question.
    Wednesday, August 25, 2010 7:28 PM

Answers

  • Hi Evil,

    Adding the MSTSCLib refernece to the WPF project and create a UserControl which contains a AxMSTSCLib.AxMsRdpClient ActiveX control. In the WPF window, add this Winform control in the WindowsFormsHost element. The following sample which is use the Remote Desktop in Winform : http://www.codeproject.com/KB/cs/RemoteDesktop_CSharpNET.aspx  The same code we can use in the UserControl for WPF.

    And according to you description, the problem is it can not change the size of the client desktop. I found a related thread but no answeered: http://social.msdn.microsoft.com/forums/en-US/windowsgeneraldevelopmentissues/thread/a9c8dd76-6e36-40b4-9a6e-cba39302b2e5/ According to this thread, we have to resize the DesktopHeight/DesktopWidth of the ActiveX control before connecting. Otherwise, it throws an exception.

       try
       {
        axMsRdpClient.Server = ServerName;
    
        axMsRdpClient.DesktopHeight = 768;
        axMsRdpClient.DesktopWidth = 1024;
        axMsRdpClient.Connect();
       }
       catch (Exception Ex)
       {
        MessageBox.Show(Ex.Message);
       }
    

    Hope this helps.

    Sincerely,

    Bob Bao

    MSDN Subscriber Support in Forum 

    If you have any feedback on our support, please contact msdnmg@microsoft.com

    -----------------------------------

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, August 27, 2010 8:46 AM

All replies

  • Hi,

    You can use VNC for remote desktop handling.

    Please check out this link.

    http://cdot.senecac.on.ca/projects/vncsharp/


    Syed Mustehsan Ikram
    Thursday, August 26, 2010 3:44 AM
  • Is there some example code on getting the VNC control into a WPF application?

    I'm currently tinkering with that myself, but an example is always better -- since I'm sure there is always a better way to do things then what I figure out on my own.

    Thursday, August 26, 2010 3:48 PM
  • UPDATE:

    I've done more work on this and am able to connect to a remote server (RealVNC), using VNC#, but I am immediately disconnected.  The client can't hold a connection to the server.

    Using the stand alone VNC client (RealVNC) I am able to connect okay.

    Any thoughts?

    Thursday, August 26, 2010 4:59 PM
  • Hi Evil,

    Adding the MSTSCLib refernece to the WPF project and create a UserControl which contains a AxMSTSCLib.AxMsRdpClient ActiveX control. In the WPF window, add this Winform control in the WindowsFormsHost element. The following sample which is use the Remote Desktop in Winform : http://www.codeproject.com/KB/cs/RemoteDesktop_CSharpNET.aspx  The same code we can use in the UserControl for WPF.

    And according to you description, the problem is it can not change the size of the client desktop. I found a related thread but no answeered: http://social.msdn.microsoft.com/forums/en-US/windowsgeneraldevelopmentissues/thread/a9c8dd76-6e36-40b4-9a6e-cba39302b2e5/ According to this thread, we have to resize the DesktopHeight/DesktopWidth of the ActiveX control before connecting. Otherwise, it throws an exception.

       try
       {
        axMsRdpClient.Server = ServerName;
    
        axMsRdpClient.DesktopHeight = 768;
        axMsRdpClient.DesktopWidth = 1024;
        axMsRdpClient.Connect();
       }
       catch (Exception Ex)
       {
        MessageBox.Show(Ex.Message);
       }
    

    Hope this helps.

    Sincerely,

    Bob Bao

    MSDN Subscriber Support in Forum 

    If you have any feedback on our support, please contact msdnmg@microsoft.com

    -----------------------------------

    This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, August 27, 2010 8:46 AM