简体   繁体   中英

WPF locking workstation programmatically

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

在此输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM