How can I prevent the system from starting or restarting in the Win32 service?

I want to prevent users from shutting down or restarting the system. my application runs as a native Win32 service (written in C ++) and under the LocalSystem account.

I've heard of the WM_QUERYENDSESSION solution: create a hidden window and grab the WM_QUERYENDSESSION to prevent shutdown.

but this solution is not very clean and also needs to create one window for each desktop. So I have to list the desktops and also take care of when the desktop is created / destroyed. All this makes the situation unpleasant!

Is there a way to detect the shutdown / restart event and prevent the system from shutting down / restarting?

(It doesn't matter if the event is turned off or reloaded, both of them must be canceled!)

+2


source to share


1 answer


You can not.

Because allowing programs to prevent shutdown / restart would be somewhat of a security vulnerability, right?



If the user tells the system to shutdown or reboot what will happen.

BTW, WM_QUERYENDSESSION is passed when the current user logs off Windows. This notice is nothing more, and if you use it in any other way, you are using it incorrectly.

+1


source







All Articles