Question

i want to prevent users from shut down or restart the system. my application runs as a Win32 Native Service (written by C++) and under LocalSystem account.

i heard about WM_QUERYENDSESSION it's solution: creating a hidden window and capturing WM_QUERYENDSESSION to prevent shutdown.

but this solution is not really clean and also have to create one window for each desktop. So i have to enumerate desktops and also care about when a desktop created/destoryed. All of these make the situation nasty!

Is there any way to detect shutdown/restart event and prevent system shutdown/restart?

(It is not important that the event is shutdown or restart, both of them must be cancelled!)

Was it helpful?

Solution

You can't.

Because allowing programs to prevent shutdown/restart would be somewhat of a security vulnerability, don't you think?

If the user tells the system to shutdown or restart, that's what's going to happen.

BTW, WM_QUERYENDSESSION is passed when the current user is logging out of Windows. It's a notification, nothing more, and if you're using it in any other way then you're using it wrongly.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top