Creating a Remote Desktop Application in VB.NET


Desktop-as-a-Service Designed for Any Cloud ? Nutanix Frame

Remote Desktop Protocol

RDP (Remote Desktop Protocol) is a protocol developed by Microsoft that provides a user with a graphical interface to connect to another computer over a network connection. Windows Remote Desktop Services is a server-based presentation virtualization component that allows a user to access applications and data hosted on a remote computer over a network.

Desktop Virtualization

Desktop virtualization is a software technology that can separate the desktop environment and its associated applications from the physical client that is used to access it. Desktop virtualization can be used together with application virtualization and user virtualization to provide a complete desktop environment management system. In Desktop virtualization, all the components of the desktop are virtualized, which allows for a flexible and more secure desktop delivery model.

Application Virtualization

Application virtualization is a software technology that envelops programs from the underlying operating system. A virtualized application behaves at runtime as if it is directly interfacing with the original operating system.

User Virtualization

User virtualization separates all of the software aspects that define a user's personality from the operating system.

Our Project

Today, you will create an application in Visual Basic.NET capable of making Remote Desktop Connections. Start Visual Basic and create a new Windows Forms project. When the project has finished loading, add three textboxes and two buttons onto it. The textboxes will be used to enter the Server name, User name, and Password. The two buttons will be used to Connect and Disconnect.

Make your form much bigger than the default size.

Use the following steps to add a reference to Microsoft Terminal Services Active Client:

  1. Click Project.
  2. Click Add Reference.
  3. On the COM tab, scroll down until you find Microsoft Terminal Services Active Client and tick it (see Figure 1).

Add a Reference
Figure 1: Add a Reference

Use the following steps to add the Microsoft Terminal Services Client Control to your Toolbox:

  1. Right-click your Toolbox.
  2. Click Choose Items.
  3. Select the COM Components tab.
  4. Scroll down until you find Microsoft Terminal Services Client and tick it, as shown in Figure 2.
  5. Click OK.

Toolbox Items
Figure 2: Toolbox Items

Your Toolbox should show two new controls inside (see Figure 3).

New tools
Figure 3: New tools

Add the Terminal Services Client Control to your form. Your form's final design should resemble Figure 4.

Figure 4: Design

The design is set up nicely now. You have to add the reference to get the Toolbox items so that we can add them onto the form.


Import the Microsoft Terminal Services Client Library namespace:

Imports MSTSCLib

Add the following code behind the 'Connect' button:

   Private Sub btnConnect_Click(sender As Object, e As EventArgs) _
         Handles btnConnect.Click


         rdpView.Server = txtServer.Text
         rdpView.UserName = txtUserName.Text

         Dim isSecured As IMsTscNonScriptable = _
            DirectCast(rdpView.GetOcx(), IMsTscNonScriptable)

         isSecured.ClearTextPassword = txtPassword.Text


      Catch ex As Exception

         MessageBox.Show("Cannot Connect", "Cannot Connect to: " _
            + txtServer.Text + " Reason:  " + ex.Message, _
            MessageBoxButtons.OK, MessageBoxIcon.Error)

      End Try

   End Sub

The Username and Server details get supplied. The IMsTscNonScriptable interface configures automatic password logon access to Remote Desktop Session Host servers. if all details are correct, rdpView will connect to the remote server and establish a connection. If anything fails, the Try and Catch block will produce the necessary exception output.

Add the next code behind the 'Disconnect' button:

   Private Sub btnDisconnect_Click(sender As Object, e -
         As EventArgs) Handles btnDisconnect.Click


         If rdpView.Connected.ToString() = "1" Then


         End If

      Catch ex As Exception

         MessageBox.Show("Cannot Disconnect", _
            "Cannot Disconnect from: " _
            + txtServer.Text + " Reason: " + ex.Message, _
            MessageBoxButtons.OK, MessageBoxIcon.Error)

      End Try

   End Sub

If connected, disconnect.

Please feel free to download RemoteDesktop_Ex, the program to accompany this article. It's found below.


Being able to create an application that can connect remotely to other users can provide you with another option to do proper application and desktop support.

About the Author

Hannes DuPreez

Hannes du Preez is an ex MVP for Visual Basic from 2008 to 2017. He loves technology and loves Visual Basic and C#. He loves writing articles and proving that Visual Basic is more powerful than what most believe. You are most welcome to reach him at: ojdupreez1978[at]gmail[dot]com

Related Articles



  • oof

    Posted by l0l on 01/03/2019 01:00pm

    In the txtserver i have to write my IP or the other computer ip?

  • Odd VS Error

    Posted by Tony on 10/10/2018 04:32pm

    Everything works well until I try to add the Terminal Services Control to my form. I get the following Visual Studio error as soon as I drop the control on the form: "Failed to create component 'AxHost'. The error message follows: 'System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. at Systems.Windows.Forms.Design.DocumentDesigner.AxToolboxItem.Create.ComponentsCore (IDesignerHost host) ..." I'm using Visual Studio version 2015. Never ran into anything like this before, and I have no idea how to "Retrieve the LoaderExceptions property for more information." Any help would be greatly appreciated. Thanks!

  • Comment

    Posted by AJ on 08/08/2018 10:47am

    Excellent one.Thank you..

  • desktop composition

    Posted by Flaviu on 02/28/2018 11:04am

    Hy, tnx for sharing, but i have a question : How can i handle desktop composition in vb code, better, how can i use and change desktop composition option in vb net code ?

  • There's no output

    Posted by John Lerry on 01/24/2018 01:50pm

    Good evening, I downloaded your program but i didn't get any output. Please help Thank you!

  • Help me

    Posted by Marcos on 11/21/2017 05:08pm

    Good afternoon all right with you? I know I have a lot of time to post, but I'm trying to use the program that you developed, but what I'm downloading is not working, and in my visual basic, the window shown in figure 4 does not appear, do you have to download any DLL, other than referencing the service? Thank you.

  • question

    Posted by uemit on 09/22/2017 12:02am

    I have this application with a Virtual PC tested, but there was no reaction neither a picture not a error message. the Virtual PC was already pingable also DNS resolution is OK. It would be nice if they could give a hint that I was developing just a remotetool to integrate this function would be pretty good

  • Programmer Analyst

    Posted by Mark on 08/07/2017 11:00am

    I was not aware of this, it potentially opens many new programming opportunities. Thanks

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date