{"id":7373,"date":"2012-06-14T07:00:00","date_gmt":"2012-06-14T07:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2012\/06\/14\/now-that-windows-makes-it-harder-for-your-program-to-block-shutdown-how-do-you-block-shutdown\/"},"modified":"2012-06-14T07:00:00","modified_gmt":"2012-06-14T07:00:00","slug":"now-that-windows-makes-it-harder-for-your-program-to-block-shutdown-how-do-you-block-shutdown","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20120614-00\/?p=7373","title":{"rendered":"Now that Windows makes it harder for your program to block shutdown, how do you block shutdown?"},"content":{"rendered":"<p>Up until Windows&nbsp;XP, applications could intercept the <code>WM_QUERY&shy;END&shy;SESSION<\/code> message and tell Windows, &#8220;No, don&#8217;t shut down.&#8221; If they were polite about it, they would also inform the user which application blocked system shutdown and why. And if they were really polite about it, they would even provide a way for the user to say, &#8220;I don&#8217;t care; shut down anyway.&#8221;\n As I noted some time ago, <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2007\/04\/16\/2148139.aspx\"> Windows Vista made it harder for applications to block shutdown<\/a>. Applications are given two seconds to clean up, and then it&#8217;s game over.\n Okay, now the game of <a href=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2012\/01\/17\/10257351.aspx\"> walls and ladders<\/a> continues. The power management folks created an escape hatch for applications which are doing things like burning a CD or controlling an industrial lathe, where shutting down the machine may not be in the user&#8217;s best interest. (The user ends up with a coaster or a factory on fire.) But since they created the escape hatch, they get to control the keys to the hatch, too.\n The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa376877(VS.85).aspx\"> <code>Shutdown&shy;Block&shy;Reason&shy;Create<\/code><\/a> function lets you register your application window with a custom message that is displayed to the user when they try to shut down the computer. When the danger-time is over, you call <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa376878(v=VS.85).aspx\"> <code>Shutdown&shy;Block&shy;Reason&shy;Destroy<\/code><\/a> to say that the coast is clear and shutdown is once again permitted.\n Mind you, these blocks are merely advisory. If users really want to create a coaster or burn down their factory, they can click <i>Force shut down<\/i>. One nice thing about making Windows responsible for the warning message is that if multiple applications want to block shutdown, all of them can be displayed in a single dialog, and the user only needs to click <i>Force shut down<\/i> once.<\/p>\n<p> Further guidance on system shutdown and the use of these functions can be found in the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms700677(VS.85).aspx\"> <i>Application Shutdown Changes in Windows Vista<\/i><\/a> document, which was the source material for most of this blog entry. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Up until Windows&nbsp;XP, applications could intercept the WM_QUERY&shy;END&shy;SESSION message and tell Windows, &#8220;No, don&#8217;t shut down.&#8221; If they were polite about it, they would also inform the user which application blocked system shutdown and why. And if they were really polite about it, they would even provide a way for the user to say, &#8220;I [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-7373","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Up until Windows&nbsp;XP, applications could intercept the WM_QUERY&shy;END&shy;SESSION message and tell Windows, &#8220;No, don&#8217;t shut down.&#8221; If they were polite about it, they would also inform the user which application blocked system shutdown and why. And if they were really polite about it, they would even provide a way for the user to say, &#8220;I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=7373"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/7373\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=7373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=7373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=7373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}