I am trying to automate workstation locking after the occurence of a WPF event. The solution is supposed to work for both x64 and x86 architectures.
I've tried the method LockWorkStation() accessible through user32.dll but it works only on x86 architecture. Is there an alternative or a specific configuration to make it work on both architectures? I thought about sending the LWin + L keyboard shortcut but the SendKeys.Send method does not seem to be usable in WPF.
string winDir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Windows);
string exec = $@"{winDir}\System32\rundll32.exe";
string command = "user32.dll,LockWorkStation";
System.Diagnostics.Process.Start(exec, command);
works on my win10 x64

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With