How can I tell if Windows Update is waiting for the system to reboot?

Raymond Chen

Raymond

Today’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’t try to install your program while the system is in a mixed state where an update is partially-installed.

Testing this from script is easy. MSDN contains sample code to do that. Let’s do it from C++. Today’s smart pointer class is (rolls dice) _com_ptr_t! Remember that Little Programs do little to no error checking.

#include <windows.h>
#include <comdef.h> // for _COM_SMARTPTR_TYPEDEF
#include <wuapi.h>  // for ISystemInformation
#include <stdio.h>  // for printf (horrors! mixing stdio and C++!)

_COM_SMARTPTR_TYPEDEF(ISystemInformation, __uuidof(ISystemInformation));

int __cdecl main(int argc, char** argv)
{
 CCoInitialize init;
 ISystemInformationPtr info;
 info.CreateInstance(CLSID_SystemInformation);

 VARIANT_BOOL rebootRequired;
 info->get_RebootRequired(&map;rebootRequired);

 printf("Reboot required? %d\n", rebootRequired);
 return 0;
}

Remember that VARIANT_BOOL uses -1 to represent VARIANT_TRUE, so if a reboot is required, you will see -1. Personally, I would treat any nonzero value as logically true.

0 comments

Comments are closed.