VMWare Workstation does something quite cool when I try to shutdown Windows while a Virtual Machine is running:
Normally, we'd see a "This program is preventing Windows from shutting down" message instead of the new "1 Virtual Machine is in use".
How does VMWare do this? I haven't been able to find any APIs about it on Google.
Enter the following command: shutdown -a . This command will cancel the scheduled shutdown for one time. You'll have to repeat this process if you want to cancel other scheduled shutdowns. Click OK (in the Run window) or ↵ Enter (in Command Prompt or PowerShell).
Prevent specific users from shutting down WindowsComputer Configuration > Windows Settings > Security Settings > Local Policies > User Rights Assignment > Shut Down the System. Double click on it > Select Users > Press Remove > Apply/OK.
You can read all about the changes introduced in Vista here. You really should read that article very carefully.
The APIs you are looking for are ShutdownBlockReasonCreate
, ShutdownBlockReasonDestroy
and ShutdownBlockReasonQuery
. Remember that these APIs are only available on Vista/2008 server up. You'll have to implement fall back behaviour on 2000/XP.
If you need to block shutdown you call ShutdownBlockReasonCreate
passing the handle to your main window and the reason as a string. This string is what is displayed in the shutdown blocked dialog, i.e. "1 virtual machine is in use" in your screenshot.
If the operation that blocks shutdown completes then you call ShutdownBlockReasonDestroy
.
Note that you must still implement WM_QUERYENDSESSION
to make all the pieces fit together. This is the part that actually blocks the shutdown.
On XP you should also respond to WM_ENDSESSION
and if your app blocked shutdown it is polite to show a message indicating why. If you don't do so then the user is left scratching his/her head as to why the computer is ignoring the instruction to shutdown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With