{"id":91551,"date":"2015-09-21T07:00:00","date_gmt":"2015-09-21T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/20150921-00\/?p=91551\/"},"modified":"2019-03-13T12:19:44","modified_gmt":"2019-03-13T19:19:44","slug":"20150921-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150921-00\/?p=91551","title":{"rendered":"How can I tell if Windows Update is waiting for the system to reboot?"},"content":{"rendered":"<p>Today&#8217;s Little Program shows how to ask whether Windows Update is waiting for the system to reboot. You might want to check this in your installer, so that you don&#8217;t try to install your program while the system is in a mixed state where an update is partially-installed. <\/p>\n<p>Testing this from script is easy. <a HREF=\"http:\/\/technet.microsoft.com\/en-us\/library\/ee692834.aspx\">MSDN contains sample code to do that<\/a>. Let&#8217;s do it from C++. Today&#8217;s smart pointer class is (rolls dice) <code>_com_ptr_t<\/code>! Remember that Little Programs do little to no error checking. <\/p>\n<pre>\n#include &lt;windows.h&gt;\n#include &lt;comdef.h&gt; \/\/ for _COM_SMARTPTR_TYPEDEF\n#include &lt;wuapi.h&gt;  \/\/ for ISystemInformation\n#include &lt;stdio.h&gt;  \/\/ for printf (horrors! mixing stdio and C++!)\n\n_COM_SMARTPTR_TYPEDEF(ISystemInformation, __uuidof(ISystemInformation));\n\nint __cdecl main(int argc, char** argv)\n{\n <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/05\/20\/135841.aspx\">CCoInitialize<\/a> init;\n ISystemInformationPtr info;\n info.CreateInstance(CLSID_SystemInformation);\n\n VARIANT_BOOL rebootRequired;\n info-&gt;get_RebootRequired(&amp;map;rebootRequired);\n\n printf(\"Reboot required? %d\\n\", rebootRequired);\n return 0;\n}\n<\/pre>\n<p>Remember that <a HREF=\"http:\/\/blogs.msdn.com\/b\/oldnewthing\/archive\/2004\/12\/22\/329884.aspx\"><code>VARIANT_BOOL<\/code> uses <code>-1<\/code> to represent <code>VARIANT_TRUE<\/code><\/a>, so if a reboot is required, you will see <code>-1<\/code>. Personally, I would treat any nonzero value as logically true. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>RebootRequired.<\/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-91551","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>RebootRequired.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/91551","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=91551"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/91551\/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=91551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=91551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=91551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}