开发者

ExitWindowsEx fails when Windows desktop Locked

开发者 https://www.devze.com 2022-12-09 19:43 出处:网络
Create a form (I\'m using .NET 2.0) with a button click event: { Thread.Sleep(3000); ExitWindowsEx(0,0); // shutdown

Create a form (I'm using .NET 2.0) with a button click event:

{
Thread.Sleep(3000);
ExitWindowsEx(0,0); // shutdown
}

Hit the button, press Left-WindowsKey + L to lock the desktop. The shutdown fails.

ExitWindowsEx returns 1 (Succes开发者_开发问答s).

Why does this API fail, and what else might fail when the desktop is locked?


The API fails because you're on a different desktop, and are therefore no longer the interactive user. From MSDN:

Therefore, if you are not the interactive user, the function can succeed without actually shutting down the computer. If you are not the interactive user, use the InitiateSystemShutdown or InitiateSystemShutdownEx function.


use http://msdn.microsoft.com/en-us/library/aa376873(VS.85).aspx. (InitiateSystemShutdown). ExitWindowsEx is 'interactive' logout.

0

精彩评论

暂无评论...
验证码 换一张
取 消