开发者

Detecting windows shutdown event

I have a windows Service always running once PC started, how would i detect using .NET 3.5 or WMI, when the user or some other application/process has requested a shutdown or reboot in wind开发者_JS百科ows.

I do not want to stop it, just log the time and who initiated the shutdown (user or process is fine, don't really need to know which process)

Thank you


Use the Microsoft.Win32.SystemEvents.SessionEnding event.

However, note that you are in a Windows Service, and this event won't fire for you unless you create a hidden form in your service. You can get one of these for free by enabling the "Interact with Desktop" option on the service.


You're looking for the SystemEvents.SessionEnding event.

Occurs when the user is trying to log off or shut down the system.


Win32.SessionEnded event gets fired when the system is being shut down. You should attach to this in your program.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜