Detecting windows shutdown event

前端 未结 3 1415
野趣味
野趣味 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.

提交回复
热议问题