How do I lock a windows workstation programmatically? [duplicate]

喜你入骨 提交于 2019-11-27 01:09:39

问题


Possible Duplicate:
Lock Windows workstation programmatically in C#

I am currently working on a visual studio windows form application that requires a function that locks the workstation. How can i make use of user32.dll to do a lock (Windows + L) when the function is called?


回答1:


I haven't tried it myself, but I found this on google

Process.Start(@"C:\WINDOWS\system32\rundll32.exe", "user32.dll,LockWorkStation");

edit: I tried it, and it works!

edit2: Here's a solution using user32.dll that doesn't start an external process.

using System.Runtime.InteropServices;

declare a method like this:

[DllImport("user32.dll")]
public static extern bool LockWorkStation();

and then call LockWorkStation();.

Voilà




回答2:


using System.Runtime.InteropServices;


[DllImport("user32.dll")]
public static extern int ExitWindowsEx(int uFlags, int dwReserved);

just call

 ExitWindowsEx(0, 0);


来源:https://stackoverflow.com/questions/13745788/how-do-i-lock-a-windows-workstation-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!