Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dears, good morning.

I developed a Windows Form application in Visual Studio (C#) that aims to lock the employees workstation that is logged into the machine by Windows.

This application is running on the employee machine via Group Policy (GPO).

Running the program locally, the code below works, but when I run via the GPO, it does not work.

Process.Start ("rundll32.exe", "user32.dll, LockWorkStation");

The only thing that worked so far was the commands:

* Application.SetSuspendState (PowerState.Hibernate, true, true); // puts the machine into hibernation
* Application.SetSuspendState (PowerState.Suspend, true, true); // set the machine to standby

I need to lock the workstation. Anyone have any idea how to solve it?


What I have tried:

I tried the following codes too, but nothing worked:

* Process.Start ("rundll32.exe", "user32.dll, LockWorkStation");
* WindowsIdentity.GetCurrent (). User;
* WindowsIdentity.GetCurrent (). Groups.Translate (GetUsuario (Name));
* WindowsIdentity.GetCurrent ().Groups.Translate(GetType (NTAccount)).ToString()
Posted
Updated 25-Oct-17 10:30am

1 solution

You cannot do what you're talking about because the code is running as LocalSystem, not the user. Locking the workstation is a user process.

You also cannot lock the workstation for another user. You USED to be able to do this, but it hasn't worked since Win Vista or 8, I can't remember which.

Why on earth would you ever want to do this anyway?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900