I am trying to implement this remote desktop project into my own application but I got some problems.. please help RRS feed

  • Question

  • Dear community,

    I am trying to implement this app . But whenever I click connect or disconnect nothing happends at all. I can remote normally with remote desktop so there is no problem with network settings.

    I did not use his lib files as it gaves me reference errors so I used the default visual studio MSTSCLib maybe that's the problem?

    Thanks in advance.

    Thursday, January 4, 2018 5:41 PM

All replies

  • How is anyone supposed to answer this without posting any of the code you have written, and you saying you didn't use the libraries suggested in the post you are trying to follow?
    Thursday, January 4, 2018 5:44 PM
  • You are more likely to get help when you provide the relevant information in the post instead of requiring others to download the code. Someone might help but you are more likely to get help if you help us help you.

    Have you looked at the comments for that article? Someone else might have had the problem. If the problem is with that source code and not the C# language then a good way to get help is to ask in the comments for that article or ask in the CodeProject forums.

    What happens when you debug the program? You can single-step through the code and see what happens.

    Sample source code usually does not have the additional error checking that real code should have. The first thing to do if you hare having problems is to add error checking, such as try and catch and checking return codes.

    Sam Hobbs

    Thursday, January 4, 2018 8:36 PM
  • Sorry for my late answer, I don't get outlook notification for some reason.

    The code is at the bottom of the article I thought it was easier to share the article / code so you know what libraries and forms are used.

                private void remoteBtn_Click(object sender, EventArgs e)
                        rdp.Server = IpAdress.Text;
                        rdp.UserName = TxtUsername.Text;
                        IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
                        secured.ClearTextPassword = TxtPassword.Text;
                    catch (Exception Ex)
                        MessageBox.Show("Error Connecting", "Error connecting to remote desktop " + Naam.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                private void DisconnectBtn_Click(object sender, EventArgs e)
                          if (rdp.Connected.ToString() == "1")
                      catch (Exception Ex)
                          MessageBox.Show("Error Disconnecting", "Error disconnecting from remote desktop " + Naam.Text + " Error:  " + Ex.Message, MessageBoxButtons.OK,

    I also have problems with running remote shutdown on the pc

                ConnectionOptions options = new ConnectionOptions();
                options.EnablePrivileges = true;
                options.Impersonation = ImpersonationLevel.Impersonate;
                options.Username = TxtUsername.Text;
                options.Password = TxtPassword.Text;
                // Make a connection to a remote computer.  
                ManagementScope scope = new ManagementScope("\\\\" + IpAdress.Text + "\\root\\cimv2", options);
                //Query system for Operating System information  
                ObjectQuery oq = new ObjectQuery("SELECT * FROM Win32_OperatingSystem");
                ManagementObjectSearcher query = new ManagementObjectSearcher(scope, oq);
                ManagementObjectCollection queryCollection = query.Get();
                foreach (ManagementObject obj in queryCollection)
                    obj.Scope.Options.EnablePrivileges = true;
                    obj.InvokeMethod("Shutdown", null); //shutdown  

    Everything works until line obj.InvokeMethod("Shutdown", null);

    I get the error System.Management.ManagementException: 'Privilege not held. '

    I found out this has to do with a windows bug in management.dll

    I have no idea to do a work arround.

    • Edited by Arancor Tuesday, January 9, 2018 10:20 AM Discovery
    Tuesday, January 9, 2018 7:46 AM
  • Have you checked the security log of the remote system to see why your connection might have been rejected?

    Are you quite sure your username has administrative rights on that computer?

    Tim Roberts, Driver MVP Providenza & Boekelheide, Inc.

    Tuesday, January 9, 2018 6:42 PM
  • For the shutdown code. I found a temporary work arround by disabling LUA limited user account in the registry of the remote computer.

    For the terminal to get to work I had to disable the second option of external connections. Only allow connections where verification is running at network level. I can't add network users to it and my user account is already at Administrator level

    I still would like to find alternatives for those work arround as they are not so safe.

    Wednesday, January 10, 2018 2:50 PM
  • Hi Arancor,

    Thank you for posting here.

    For your question, I try to download the source code from the link you provided. The code does not work for me as well.

    You could download the source code from the link below. It uses VB.NET. You could convert VB to C# online. The code works well on my side. Please note that the application need to run as admin.

    If you want to convert the code from VB to C#, you could try to use the online tools.

    Best Regards,


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

    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Thursday, January 11, 2018 7:55 AM