views:

429

answers:

1

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!)

+1  A: 

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.

Ian Kemp
I am developing a software for managing cybercafé.One of the software features must be preventing systems from shutting down. So i don't need a 100% solution but it should prevent shutdown is regular cases.So in this case it is not security vulnerability.
Isaac
Microsoft doesn't care about what's best for one person; they care about what's best for the majority of their users. Allowing programs to prevent restart/shutdown is definitely a security vulnerability for the majority of Windows computers out there.If you really, really need this sort of functionality, you should look at Group Policy settings to disable restart/shutdown from the Start menu. Alternatively, contact the author of one of the utilities from:http://www.raymond.cc/blog/archives/2008/09/25/prevent-cancel-and-abort-a-windows-system-shutdown-or-restart-when-application-is-running/
Ian Kemp
I need a way to prevent the shutdown just when i want. Sometimes shutdown should be allowed and sometimes should be prevented.Group Policy applies rules on Explorer. So when i change a policy i have to restart Explorer.Exe. So i have to detect current user and Imprestonate it and CreateProcess with his token. Am i right?
Isaac