Detecting windows shutdown event

前端 未结 3 1399
野趣味
野趣味 2020-12-11 09:34

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 o

相关标签:
3条回答
  • 2020-12-11 09:57

    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.

    0 讨论(0)
  • 2020-12-11 10:03

    You're looking for the SystemEvents.SessionEnding event.

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

    0 讨论(0)
  • 2020-12-11 10:13

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

    0 讨论(0)
提交回复
热议问题