fbpx

Remote Desktop using C#.NET – CodeProject

Image 1

Introduction

Remote Desktop Services is one of Microsoft Windows components to access a remote computer through the network. Only the user interface of the application is presented at the client. Any input is redirected over to the remote computer over the network.

At work, we use Remote Desktop a great deal. It allows us to login to a remote server to perform health checks, deploy applications, troubleshoot problems, etc. We also use remote desktop often when we do WFH (work from home).

Why do you want to write a .NET application to do this when you have the MS Terminal Services client available from OS? Well, consider if you want to work on 3 different application servers at the same time and want to toggle between these 3 servers quite often. With the MSTSC, we will be running 3 different clients for the 3 servers and it is difficult to manage the working environment. In .NET, you can develop an application with tab control to load remote desktop sessions in different tabs in one window.

Background

We will be using AxMSTSCLib an ActiveX component in our program to connect to the remote computer. It’s not that hard to build a remote desktop application in .NET. Microsoft has a “Microsoft RDP client control” ActiveX control that we will be using in our application.

This is How We Do It

We will start by creating a Windows application in the Visual Studio IDE.

Add a reference to “Microsoft Terminal Services Control Type Library” from the COM tab. This will add MSTSCLib.dll to the project.

Sample Image - maximum width is 600 pixels

To add MSTSC to the toolbox, right click the toolbox and select “Choose Items…”. Now add “Microsoft Terminal Services control from the COM tab.

Sample Image - maximum width is 600 pixels

Drag the newly added control from toolbox to the form.

Add 3 textbox and 2 button controls to the form:

Sample Image - maximum width is 600 pixels

Connect Button – Click Event

Here is how we write the Connect button click event.

rdp.Server = txtServer.Text; rdp.UserName = txtUserName.Text; IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx(); secured.ClearTextPassword = txtPassword.Text; rdp.Connect();

Now assign the properties (Server, UserName) of RDP control with the textbox values.

Here’s how easy it is to login to remote machine. However there is one catch, there is no direct method in RDP control through which you can pass the username and password to login to the remote desktop.

Due to security reasons, you have to implement an interface (IMsTscNonScriptable) to cast it separately.

IMsTscNonScriptable secured = IMsTscNonScriptable)rdp.GetOcx(); secured.ClearTextPassword = txtPassword.Text;

Disconnect Button – Click Event

To disconnect from the remote desktop session, we just need to call the Disconnect() method.

Before disconnecting, we want to ensure that the connection is still available. We don’t want to disconnect if it is already disconnected (very clever, huh).

if (rdp.Connected.ToString() == “1”) rdp.Disconnect();

That’s all folks!

History

  • 5th November, 2009: Initial version

Source

15 thoughts on “Remote Desktop using C#.NET – CodeProject”

  1. I run a vape shop web directory and we have had a listing from a vape store in the United States that additionally markets CBD goods. A Calendar month later, PayPal has contacted use to say that our account has been restricted and have requested us to remove PayPal as a payment method from our vape shop directory. We do not offer for sale CBD goods like CBD oil. We simply provide advertising and marketing professional services to CBD companies. I have had a look at Holland & Barrett– the UK’s Leading Wellness Merchant and if you take a good peek, you will witness that they promote a rather extensive series of CBD product lines, particularly CBD oil and they also happen to take PayPal as a payment method. It emerges that PayPal is employing twos sets of rules to many different companies. Because of this stipulation, I can no longer accept PayPal on my CBD-related site. This has restrained my payment possibilities and currently, I am intensely contingent on Cryptocurrency payments and direct bank transfers. I have checked with a lawyer from a Magic Circle law firm in London and they stated that what PayPal is doing is entirely against the law and discriminatory as it should be applying an uniform benchmark to all companies. I am still to consult yet another legal representative from a US law office in London to see what PayPal’s legal position is in the USA. For the time being, I would be highly appreciative if anybody here at targetdomain could offer me with alternative payment processors/merchants that work with CBD companies.

  2. Attractive section of content. I just stumbled upon your site and in accession capital to assert that I get actually enjoyed account your blog
    posts. Any way I’ll be subscribing to your feeds and even I achievement you access consistently rapidly.

  3. Hello There. I discovered your blog using msn. That is a very neatly written article.

    I will make sure to bookmark it and return to
    learn more of your useful info. Thank you for the post.
    I will certainly comeback.

  4. I want to show appreciation to this writer just for rescuing me from this particular predicament. Right after exploring throughout the the net and getting basics that were not productive, I was thinking my life was well over. Existing without the presence of solutions to the issues you’ve resolved as a result of this short article is a serious case, as well as ones which might have badly damaged my career if I had not come across your blog. Your good capability and kindness in playing with every item was vital. I don’t know what I would have done if I had not encountered such a subject like this. I can at this time look ahead to my future. Thanks a lot very much for the professional and effective help. I will not think twice to refer the sites to any individual who will need tips on this problem.

  5. Thanks for the ideas you have contributed here. Additionally, I believe there are several factors which will keep your automobile insurance premium all the way down. One is, to consider buying vehicles that are within the good listing of car insurance corporations. Cars which might be expensive are usually more at risk of being robbed. Aside from that insurance is also depending on the value of your car or truck, so the higher priced it is, then higher the premium you only pay.

Leave a Comment

Your email address will not be published. Required fields are marked *

Need backlinks? Publish your articles on RemotePro
This is default text for notification bar
%d bloggers like this: