UPDATE : Here is a sample code for Vista only.
ShutdownBlockReasonCreate
Running the program then initiating a shutdown will display the Windows feature.
As things seems to have changed a little in Windows 7, it doesn’t work with it. I will post an updated version of it, when the documentation is available.
Sometimes you need to handle a shutdown that has been accidentally initiated …
(Yes it can happen, at least for me).
For example in XP, when you have an application running and initiate a shutdown, a small window appears, saying that the application is not responding :
By simply pressing Cancel you were able to abort the shutdown process.
Now on Vista, things have a changed a little, there is a new more user-friendly interface that appears when you try to shutdown while other applications are running :
There’s an API in Windows that you have to use, though.
In fact that API is more subtile than it looks, because of lack of examples and that you have to place these functions in a precise place in your code.
(Note that while the two provided links are unknown to each other, there are complementary informations on them !)
You have to request that you need to block the shutdown process, probably because the application is doing whatever you think, is a critical operation.
However, according to Microsoft, it is not recommended practice.
Your application shall never block a shutdown process, especially if it’s a critical shutdown (one initiated by the user, from the shutdown button present on the Start menu).
A better practice, would be to save your application’s data and shut it down.
I needed this, so I started using the API but ran onto some issues …
Numerous examples on the web didn’t work for me, when not C++ at best I could see the new UI for 5 seconds only.
Now what I wanted is, just like in Outlook, when you shut down while it is running, the system waits for it to finish Send/Receive then it continues the shutdown process.
On the documentation it seems that the content has not been verified, there are duplicate paragraphs and actually, we can make Vista wait more than 30 + 5 seconds (just as Outlook does or seems to), even in a critical shutdown !
There is also an obscure function, so obscure that Microsoft removed its documentation, CancelShutdown. It does what it says even under Vista and 7, it is able to (need to confirm that) cancel shutdown on these platforms.
We’ll look at all the coding needed for that, on part 2 …

