Trying to remotely lock a computer on my network with C#

  • Thread starter Thread starter EnviroSE
  • Start date Start date
E

EnviroSE

Guest
I am looking for a way to lock any computer on our network remotely using C# in a program I am building. I have scoured the internet trying to find some piece of code that will allow me to do this. Here is the code I have been trying to use:



ConnectionOptions disableComputer = new ConnectionOptions();
disableComputer.Username = "domain\username";
disableComputer.Password = "password";
disableComputer.Authority = "Kerberos:domain\\computerName";
disableComputer.Impersonation = ImpersonationLevel.Impersonate;
disableComputer.EnablePrivileges = true;
//disableComputer.Context = null;

ManagementScope scope = new ManagementScope("\\\\computerName\\root\\cimv2", disableComputer);
scope.Connect();

ObjectGetOptions objectGetOptions = new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(scope, managementPath, objectGetOptions);
ManagementBaseObject inParameters = processClass.GetMethodParameters("Create");
inParameters["CommandLine"] = "rundll32.exe user32.dll,LockWorkStation";





I tested the connection with a query script I found on MSDN, and it was able to connect to a remote laptop I have been testing with. But the second half of the script (below scope.Connect) has not worked. I have managed to lock my own machine several times, but I cannot seem to lock any other computer on the network.

The purpose of this script is so when an employee is let go, our HR department can simply select a name and disable that employees account. As part of the process, I want it to lock the employees computer so they cannot access their machine after being let go.

Can anyone please offer a suggestion that can get me on the right track and let me know what I am doing wrong?

Continue reading...
 
Back
Top