<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Sharp World &#187; shutdown</title>
	<atom:link href="http://sharpmix.net/blog/tag/shutdown/feed/" rel="self" type="application/rss+xml" />
	<link>http://sharpmix.net/blog</link>
	<description>It&#039;s about C# and video games !</description>
	<lastBuildDate>Fri, 18 Sep 2009 15:43:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Block system shutdown</title>
		<link>http://sharpmix.net/blog/2009/06/12/block-shutdown-in-vista-shutdownblockreasoncreate/</link>
		<comments>http://sharpmix.net/blog/2009/06/12/block-shutdown-in-vista-shutdownblockreasoncreate/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 13:32:45 +0000</pubDate>
		<dc:creator>Abdallah Fdal</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[shutdown]]></category>
		<category><![CDATA[ShutdownBlockReasonCreate]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Win32]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://managedworld.wordpress.com/?p=8</guid>
		<description><![CDATA[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&#8217;t work with it. I will post an updated version of it, when the documentation is available.
Sometimes you need to handle a shutdown [...]]]></description>
			<content:encoded><![CDATA[<h3>UPDATE : Here is a sample code for Vista only.<a href="http://sharpmix.net/blog/wp-content/uploads/2009/09/ShutdownBlockReasonCreate.zip"></a></h3>
<h3><a href="http://sharpmix.net/blog/wp-content/uploads/2009/09/ShutdownBlockReasonCreate.zip">ShutdownBlockReasonCreate</a></h3>
<h3>Running the program then initiating a shutdown will display the Windows feature.</h3>
<h3>As things seems to have changed a little in Windows 7, it doesn&#8217;t work with it. I will post an updated version of it, when the documentation is available.</h3>
<p>Sometimes you need to handle a shutdown that has been accidentally initiated &#8230;</p>
<p>(Yes it can happen, at least for me).</p>
<p>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 :</p>
<p><a href="http://sharpmix.net/blog/wp-content/uploads/2009/06/xpend4.png"><img class="aligncenter size-full wp-image-34" title="XP shutdown" src="http://sharpmix.net/blog/wp-content/uploads/2009/06/xpend4.png" alt="XP shutdown" width="354" height="250" /></a></p>
<p>By simply pressing <em>Cancel </em>you were able to abort the shutdown process.</p>
<p>Now on Vista, <a href="http://msdn.microsoft.com/en-us/library/ms700677%28VS.85%29.aspx">things have a changed a little</a>, there is a new more user-friendly interface that appears when you try to shutdown while other applications are running :</p>
<p><a href="http://sharpmix.net/blog/wp-content/uploads/2009/06/ui1.jpg"><img class="aligncenter size-full wp-image-33" title="Vista's new shutdown UI" src="http://sharpmix.net/blog/wp-content/uploads/2009/06/ui1.jpg" alt="Vista's new shutdown UI" width="496" height="414" /></a></p>
<p><a href="http://msdn.microsoft.com/en-us/library/aa376882%28VS.85%29.aspx">There&#8217;s an API</a> in Windows that you have to use, though.</p>
<p>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.</p>
<p><em>(Note that while the two provided links are unknown to each other, there are complementary informations on them !)</em></p>
<p><strong>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.</strong></p>
<p>However, according to Microsoft, <span style="text-decoration: underline;">it is not recommended practice</span>.</p>
<p>Your application shall never block a shutdown process, especially if it&#8217;s a critical shutdown (one initiated by the user, from the shutdown button present on the Start menu).</p>
<p>A better practice, would be to save your application&#8217;s data and shut it down.</p>
<p>I needed this, so I started using the API but ran onto some issues &#8230;</p>
<p>Numerous examples on the web didn&#8217;t work for me, when not C++ at best I could see the new UI for 5 seconds only.</p>
<p>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.</p>
<p>On the <a href="http://msdn.microsoft.com/en-us/library/ms700677%28VS.85%29.aspx">documentation</a> 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 !</p>
<p>There is also an obscure function, so obscure that Microsoft removed its documentation, <em>CancelShutdown</em>. It does what it says even under Vista and 7, it is able to (need to confirm that) cancel shutdown on these platforms.</p>
<p><span style="text-decoration: line-through;">We&#8217;ll look at all the coding needed for that, on part 2 &#8230;</span></p>
]]></content:encoded>
			<wfw:commentRss>http://sharpmix.net/blog/2009/06/12/block-shutdown-in-vista-shutdownblockreasoncreate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
