Controlling PC And Remote Access via lan in c#

Mahamud Hasan
Wasif Islam
kishor datta gupta

we  develop a software which perform basic PC controlling operations and  complete remote access using C#. With our software we can establish a connection to any computer via the LAN in just a few seconds and remotely control this computer just as if you were sitting in front of it.

our software can able to do following tasks

  • We can connect server pc and client pc.
  • Maximum 5 clients can connect to the server.
  • Server and client can transfer data with each other.
  • Only server can tranfer file to the client.
  • Server pc can shutdown, restart and logoff to the client pc.
  • Using remote access server pc can see the desktop of the client.
  • Server pc can browse client pc and install any kind of software.
  • Server pc can access to the computer to be serviced and it can perform any action even if no-one is sitting in front of it.

Features:Simple implementation of a TCP client server relationship

When the server program is run, it will indicate at which IP it is running and the port it is listening to. Using Tcp listener server can listen its ip address and port. “Dns.GetHostByName(Dns.GetHostName()).AddressList[0];” –Using this code we get the server ip address. At the same time a thread will be running. This thread will waiting for client connection.

Now run the client program and write down the server ip address. Then press the “Connect” button and it establishes a connection with the server.

When a connection is established the server will display the client IP address from where it has accepted the connection and client will ask for the string which is to be transmitted to the server. The server on reciept of the string will display it, send an acknowledgement which will be recieved by the client.

The client can be either run from the same machine as the server or from a different machine. If run from a different machine then a network connection should exist between the machines running the server and client programs.

When any client connect with the server then from the server display a combobox named “Client IP List” contains all client IP.

When connection is established between server and client then server and client can transfer message with each other.

When server send message then client recieve this message. At the same time client can send message to the server from the Message textbox.Then server also recieve data from the client. Server can transfer file to the client. Using Networkstream server can transfer file. When we press File Transfer button then a file dialoug box is open. Then select a file and send it.

There are controll operations that the server will perform to the client. If server want to shut down the client pc then server can select the shut down button and activate it. Then client pc will shut down. Server can do three operations if it want. These are Shutdown , restart and log off.

We use Remote Desktop a great deal. Using remote access server can browse the client PC. All kind of operation can be performed by the server when remote is active,

For that we get a help from a codeproject article . Thanks to it we make a very effective remote access,

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.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.

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

Drag the newly added control from toolbox to the form.

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;

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;

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.

if (rdp.Connected.ToString() == "1")

Though we have developed our software using the platform independent programming language C# but our software is not totally platform independent at all. Because our software only run in the .net framework version 3.5. But we are tried our best to do that. There are a few limitations in our software cause it can remotely connect to only one client pc at a time.

Full source code of this software is here

About kishor datta gupta

Graduate Research Assistant at University of Memphis Software Engineer at Silicon Orchard LTD. Former Research Assistant at Lamar University Former Software Engineer at Samsung R&D Institute Bangladesh Studies Ph.D. Computer Science at University of Memphis Studied Masters of Science in Computer Sciences at Lamar University Studied BSC in CSE at Khulna University of Engineering and Technology Studied HSC (completed) at Chittagang college 04-06 Studied High school at ST. Placid's High School'04 Studied Junior Secondary School at Saint Mary's School Lives in Memphis, Tennessee
This entry was posted in C#, Winform app and tagged , , , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

140 Responses to Controlling PC And Remote Access via lan in c#

  1. NILESH says:

    sir…. i want this software for my project submission….!!!!
    plz help me…..

  2. Prashantha Achary says:

    Hi Kishor..

    I am not able to download the source.. When i click on download link it is redirect to “” site.. From here how to download ?
    Please help

  3. Shahzad says:

    I downloaded ur project.It’s brilliant work done by you.But i am facing one error as multiple clients get added into combobox then only the recently joined client can be contacted by server i.e if there are 2 pc’s joined then the later one i.e pc 2 is only interacted with server despite the selection of IP of Pc 1 in combobox.
    Plz help me in this matter.

  4. Shahzad says:

    I downloaded ur project.It’s brilliant work done by you.But i am facing one error as multiple clients get added into combobox then only the recently joined client can be contacted by server i.e if there are 2 pc’s joined then the later one i.e pc 2 is only interacted with server despite the selection of IP of Pc 1 in combobox.
    Plz help me in this matter.
    Thank you.

  5. Prashantha Achary says:

    Hi Shahzad ,
    What you have to do is , every time whenever clients (PC) get connects you have to store the socket in collection (Arraylist / Hash table) . And also u have to remove the client from collection whenever it get disconnect. So at any point of time u can access the connected clients .

  6. Prashanth achar says:

    Hi Here is the code,

    Step 1 : Create class called ClientObject to hold the state of the client.
    public class ClientObject
    public IPAddress m_IPAddress = null;
    public TcpClient m_tcpClient = null;

    public ClientObject(TcpClient tcpClient)
    m_tcpClient = tcpClient;
    m_IPAddress = ((System.Net.IPEndPoint)(tcpClient.Client.RemoteEndPoint)).Address;


    step 2: Create a hash table
    // Hash table is used to keep track of sockets that are designed to //
    // communicate with each connected client (identified by DID). It is //
    // made a synchronized HashTable for thread safety //
    public System.Collections.Hashtable m_objHashTable =
    Hashtable.Synchronized(new System.Collections.Hashtable());
    step 3: create a delegate to add clients to hash table asynchronously
    public delegate void AddClientToCollection(ClientObject objClient);

    Step 4: Create a lock object for accessing Hash table
    public Object m_objHashTableLock = new object();
    step 5: In performConnect method add below 2 lines of code after
    tcpClient = myList.AcceptTcpClient(); this line
    //Add these 2 line code
    ClientObject objClient = new ClientObject(tcpClient);
    this.Invoke(new AddClientToCollection(OnClientConnectedCallback));

    step 6 : Finally add this method
    // This call back is called whenever a client connects to the server
    public void OnClientConnectedCallback(ClientObject objClient)
    ClientObject objClientEntry = null;

    lock (m_objHashTableLock)
    // Add to the table only if client is already not present
    if (m_objHashTable.Contains(objClient.m_IPAddress) == false)
    // Add client to hash table – A NEW CONNECTION
    m_objHashTable[objClient.m_IPAddress] = objClient;

    // Now the control can come here for two reasons //
    // 1. Correct socket/connection and a new packet has arrived //
    // this is the case for most packets (normal operation). //
    // 2. Reconnection had happened, old connection retained in //
    // the server and this is the first packet from the //
    // client with the communication happening with new //
    // socket. //
    objClientEntry =

    // Now detect if it is case 1. //
    // This can be accomplished by checking if the socket ID //
    // in the hashtable (corresponding to the clientobject) //
    // is same as what is received in this callback. //
    if (objClientEntry.m_tcpClient ==
    // Do Nothing as this is the expected case when a //
    // packet comes from a connected client //
    // Now control comes here only if it is a reconnection!! //
    // Why? because, there is a stale socket lying in the //
    // hash table in the name of this client (from where the //
    // packet is received) from a different socket id!, //cp
    // hence it has to be properly handled. //

    // Close the stale socket handle in hashtable

    // Clear the entry in the hashtable for this DID

    // Release object assigned during connection

    // Recognize this (client – recevied now) as the //
    // valid connection and insert it to hashtable //
    m_objHashTable[objClient.m_IPAddress] = objClient;

    catch (Exception ex)


    Hope you understand …. 🙂

    • kishordgupta says:



    • Shahzad says:

      Thanks a lot Prashanth achary…
      Really superb job….if possible for u can u plz mail me the updated copy of this project to mail address.
      My mail id :
      Also if possible please provide some guidance on following…
      *I have picturebox on server machine for recieving & displaying client desktop.I want to do is display specific client desktop in specific picturebox but i m unable to do this.Plz help me.
      Thank You.

  7. Prashanth achar says:

    Hi Shahzad,
    In my application , I am not displaying client computer in picture box, instead i am showing in Tree view with Client Computer name and its IP adress. U can select one of the client from the tree view and send the command to client system from menu item.

    Ok i am sending code to ur email id.

    • kishordgupta says:

      can u plz send me also, my mail id is

      and can add this in my blog with ur name (plz send a profile address fb,linkedin, twitter)

      • Prashanth achar says:

        Hi Kishor,

        My server application is completely deferent than ur code. But functionality wise one and same. I am still trying improve the code as well as UI.
        Any way i am sending the code to u.
        Hope u will like that.

        • Shahzad says:

          Thanks a lot Prashanth…
          But i tried ur code its throwing an exception as soon as client connects to server in line below as parameter count mismatch.
          The line is: this.Invoke(new AddClientToCollection(OnClientConnectedCallback));
          what could be this exception about & how to deal with it.

          • Prashantha Achary says:

            Sorry Dude,
            I hurry i have done the code for you without testing ,

            Here is the solution.
            Step1 : Create a instance of the delegate for which we have created for adding clients to the collection like this
            //(Add this line after declaring the delegate )
            AddClientToCollection objAddClientToCollection;

            Step 2 : Initialize the delegate (inside the form1 method)
            objAddClientToCollection =
            new AddClientToCollection(OnClientConnectedCallback);

            step 3 : Replace
            this.BeginInvoke(new AddClientToCollection(OnClientConnectedCallback));
            this line of code with

            in performConnect method.

            This will work…… 🙂

            • Shahzad says:

              1)It works but my problem remains unsloved i.e when client get connected to server i am unable to contact earlier connected pc’s.when i select earlier connected IP from combobox.It only send message to last connected client.
              2) I also recieved ur cybercafe code but when client connects it throws an exception as “Exception has been thrown by the target of an invocation.”

              Plz help me solve out these 2 problems

            • Anonymous says:

              sir can you pls send me a code pls? and the interface .. because i cannot download the source code in the site given .. if you can send it to me its a big favor for me .. tnx in advance .. i m very need this because I need for my case study .. tnx a lot ..
              this is my email

          • rohit says:

            plzz send me source code of this project if u got it.. plzz plzzz help me plzzz……
            email ID

        • Anonymous says:

          Sir will u plz send me the code ?????
          my email address is

  8. Swagata Prateek says:

    A-W-E-S-O-M-E dada. I’ll obviously look on it from you. 😀

  9. razibdeb says:

    Really great.
    Thanks a lot for sharing this.

  10. fadedreamz says:

    মাথা নষ্ট হইছে … খুব ভাল … চালায়ে যাও

    • kishordgupta says:

      ভাই, এই প্রজেক্টের অর্ধেকের বেশি কাজ আপনার ই করা । আর আপনি কন মাথা নষ্ট?

  11. pravin hase says:

    Hello sir,
    I unable to download project.
    please help me.

  12. waqas shahid says:

    i am unable to get remote access using this code in client ip text box i write the ip of client but in user name and password box what i have to write?
    comp. name or user name?
    need help!

  13. waqas shahid says:

    an early reply for help is required!

  14. Pravin says:

    Thanks sir. I downloaded this. In this remote machine access not work. Sir I want to show the shared file of server on client and vice versa as like regular file sharing and also want to set the permission for the server share folders. Means if server shares the folder “abc” then client should the access the read only. if client needs other permission then he will request to server. After permitting the server permission he can use this file. How can i do this? Please help me.

  15. Anonymous says:

    The program was very good but i can’t use Remote Access!!!
    i am unable to get remote access.
    i entered ip of client in Client Ip textbox but in user name and password box what i have to write?
    If you have complete documentation with more details for this application,I would be grateful if you can upload it.

    Thanks a lot

    • Wasif Islam says:

      You have to enter Client PC’s username and his PC’s password…To know the username of client PC, click to the start menu of that pc and know the Administrator name and Password…To remote login you have to know the client PC’s IP,administrator name and password.
      I hope it will work.

    • Wasif Islam says:

      You have to Enter Client PC’s administrator name in the user name field and password to password box.To remote login you have to know Client PC’s IP, Administrator name and administration password.
      Hope this will work.

    • Wasif Islam says:

      You have to enter Client PC’s Administrator name and his pc’s password.
      To remote login you have to know Client PC’s IP, administrator name and administrator password.
      Hope this will help you…

      • Anonymous says:

        But it really doesn’t work!
        Does anyone already tried this program?

        • Zeeshan says:

          For more Help plz specify the error u r getting n also mention what ur entering in the textboxes….Also try this out….
          1) Verify there is full connectivity present i.e. LAN connection.
          2 ) U have to enter username of windows account & its password of client or network PC.If network pc has no password assigned u have to assign it & then try it out….
          3) If it still won’t work verify that remote connection must be enable from system properties i.e. to verify just follow this…
          a) Right Click “My Computer —> Properties”.
          b) Select “Remote” Tab…
          c) In that just verify that “Allow users to connect remotely to this computer” is checked…..if not make it checked..
          Try out if any prob….contact

          • Anonymous says:

            Dear Zeeshan

            I did all these things but can not be performed.
            And when I press the Connect button several times tandem with the face I get the following error:
            (error connecting to remote desktop. error Hresult E_fail…) ???!!!

            Thanks for the tips.

  16. Frank says:

    This is really amazing!
    I am looking for a long time.
    Why the remote control does not work?
    can You Test again this application and if it’s running, upload this project again???


  17. karthick says:

    while viewing client pc..the client pc get to avoid this

  18. Anonymous says:

    hi, great work can i ask will this work if i try to access another computer desktop via internet, if not can you guide me how it will be possible. Any help appreciated.
    Thanks and great work

  19. Shamim Moral says:

    Controlling pc & remote access by ID via Internet in c#

  20. Mohan Raj says:

    HI remote viewing is not working !

  21. Anonymous says:

    hi good morning ser, i have a littile question..
    sir how can i get server time if we have server name.
    pls help me

  22. aftab says:

    client screen sharing version is not working inn your project even if i write ip , username , password of that client. i debugged it and found its getting connect but their is no display ! plzz help me …

  23. it is not working in win 7 update version ans some of xp’s update may be there some change in windows remote control system.

    it was my 2nd year project , now i m completely far away from computer networking. so i cant help u, but u can post ur problem in stackoverflow, i m sure u can get help

  24. jaymin says:

    can u plz give me code for for getting connected pc on lan??\
    my id=

  25. jaymin says:

    actually m searching foe remotly installer software..
    its my last year project as well as m searching foe code for that plz help me out…

  26. Anonymous says:

    if possible for u can u plz mail me the updated(multiple client access) copy of this(Controlling PC And Remote Access via lan in c#) project to mail address.
    My mail id

  27. amit says:

    hello kishore.. i used ur project and liked it, but yet there is some problem in my view. Plz resolve my prob.. the prob is that I dont want to logoff the client machine whenever I remotely access that machine. i.e. that user doesnt know what is happening in his machine….. Kindly help me for the same….

  28. vinaya says:

    sir we want to implement the remote access pc concept over internet for our project
    can you please help us

  29. Ria says:

    My problem is ,how to prevent the logging off of client machine in remote access.I want that client can see what the server is doing with client macine,in
    Pls….. if anyone know,send me code in c# as soon as possible…….

  30. ryan106 says:

    Hi Sir can you please send the source code to my email:

    I wasnt enable to download your source code on your site.

    Is it possible to control client windows forms and form.hide from server winform application? Can i have a sample..

    Thanks in Regards

  31. Akhilesh says:

    Can You send The Source code on my email Id
    Thanks In Regards

  32. Rammohan says:

    Sry..but i am not able to download the source code from the above link…can u plz give an another link from where i can get this…..thanks…My mail id is:

  33. Anonymous says:

    Sry Sir, i am not able to download the source code from the above link…can u plz give an another link from where i can get this or send the source code in my mail, its urgent sir i need it…..thanks,

  34. Anonymous says:

    Srry Sir., I am not able to download the source code from that link. If you are so kind-enough, can you mail this source code to the following mail.
    I think this will help me to complete my project. Sir it is urgent………
    Thank you.

  35. Neeraj Chauhan says:

    Hi Kishor,

    Could you please e-mail me the source code as the mentioned download links are not accessable.

    Neeraj Chauhan

  36. Qasem Hammouri says:

    can you send my the file coz the link not found !!

  37. Anonymous says:

    downloadlink not working please can u send me download link or file on my mail id

  38. tanvir says:

    sir plz send me the source code of this project on my email id “”
    download link is not working sir plz.

    for project subbmission

  39. waw says:

    Hi Sir can you please send the source code to my email:wawza_nakarin [at]

    thank you

  40. Abhishek Kumar says:

    Please send the source code of this project at as I had to use this in my project and I want to enhance it if possible.

  41. Praveen says:

    Sir please send this code to my mail id

    Praveen S

  42. Anonymous says:

    Sir please send this code to my mail id


  43. Anonymous says:

    You’ve done awesome work. Pls send this code to my email

  44. Rahul says:

    Download link is not working plz send this code to my email


  45. ad says:

    Download link is not working :S

  46. Anonymous says:

    Pls send the code …..

  47. Victor says:

    Sorry sir I dont understand where did you came up with variable rdp where did we create that object?

  48. waqas says:

    Brother your given link is not working….can u send me the source code

  49. rohit says:

    plzz plzzz send me source code… of thos project.. downlopading link is nt working.. plzz plz… send me or contact me.. help me buddyyy.. email ID

  50. Mehmet says:

    can you please e-mail me
    the source code as the mentioned download links are not accessable.
    kind regards

  51. amara says:

    plzzzzzzzzzzzzzzzzz sir send ur proj code file at this e-mail id
    i need it todayyyyyy our tomarrow………………….

  52. amara says:

    i face two errors ” rdp don’t exist in current contaxt” and “the type our namespace IMsTsc nonscriptable”

    sir plz help me for resolving these errors……………………………….

  53. harshvarudkar says:

    Hello sir, the download link is not working plz help me and mail me on

  54. Shahzad Seraj says:

    Can you plz send me code on my mail ID

  55. ROYLAND says:

    Hello sir.. Can you please email to me the code this is my email address

  56. william says:

    thank you for the article.
    could you reupload it or send it to my email, please? reklamarsiv[at]

  57. Anonymous says:

    Send me this Project.this mail

  58. Anonymous says:

    plzz send me source code of this project if u got it.. plzz plzzz help me plzzz……

  59. kumar says:

    Plz send the source code to my

  60. sankalp says:

    plz send me the source code..

  61. Anonymous says:

    I’ll be glad you for sending me the source code. Here is my e-mail address:

  62. Anonymous says:

    please send the source code at

  63. Vipul says:

    Hi Sir,

    Can you send this source code on

    Thanks in advance.

  64. This project is extremely awesome.
    Will you please send me the source code on my email address.

  65. Alexandr says:

    Hello !! I can’t download the code from the link above. Can you please send the code to ? thanks a lot !!!!

  66. Michael says:

    Hi, I can’t download your Full Source Code.. Can you please send the source on my email address :
    Thanks a lot for your help…

  67. praveen says:

    Hello Sir,
    This is the great project, your work is awesome.
    But sir downloading link is not working
    Plz plz send me this project at my mail

  68. adab says:

    This great your project but I can not download it I would send:

  69. Divya says:

    Hi sir this project is grt .. i am not able to download can you mail me dis project pls my id

  70. Divya says:

    can you tell me how to set the properties of user name and password

  71. Arup Dolui says:

    The source code file is removed..I cannot download it…Please help me out Sir…Thank you.
    Please mail me the code —-

  72. om says:

    hi sir there is d problem on source code page ,,,,, and i want this code so plz sir send me code on

  73. Rui says:

    Anyone have the project to download or to email???

    my email is

    I would apreciate a lot


  74. sumit saurav says:

    Plz send me the code
    I am not able to download the code from the link.
    Any one who have got the complete code please send me.

  75. waleed ahmed says:

    plz sir send ur project code file at this e-mail :
    I am not able to download the code from the link.
    i need it today our tomarrow………………….

  76. Daneal says:

    I can’t download the code. please send the code to

  77. I can’t download the code. please send the code to
    please send the code to
    thank you

  78. howardteoh says:

    I can’t download the code. please send the code to
    please send the code to
    thank you

  79. MJ says:

    Sir please send the code to me.. ^_^

  80. stargag says:

    please send me source code

  81. Anonymous says:

    which library files did u use please say?????

  82. kamyarpyar says:

    Many users have demanded the source of your application. Are you planning on releasing the source freely any time soon? Thanks.

  83. Anonymous says:

    please send me your code i can’t download it..plz send me your code on
    i really need it.

  84. Anonymous says:

    Sir i can not download the code from the link.
    Would you plz send me the project code file at this e-mail :
    i really need help from it for my project

  85. Can you please send your code on this email id

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s