如何检查机器是否因为装了Windows更新而需要重新启动 By Dawei XU Published Sep 22 2015 Contents 今天的The Old New Thing: How can I tell if Windows Update is waiting for the system to reboot?介绍了如何检查机器是否因为装了Windows更新而需要重新启动。下面是稍作修改的CPP和C#的代码。 12345678910111213141516171819#include <atlstr.h>#include <wuapi.h> #include <iostream>int _tmain(int argc, _TCHAR* argv[]){ CoInitialize(NULL); { CComPtr<ISystemInformation> info; info.CoCreateInstance(CLSID_SystemInformation); VARIANT_BOOL rebootRequired; info->get_RebootRequired(&rebootRequired); std::cout << rebootRequired; } CoUninitialize(); return 0;} 1234Type t = Type.GetTypeFromProgID("Microsoft.Update.SystemInfo");object s = Activator.CreateInstance(t);var needReboot = t.InvokeMember("RebootRequired", BindingFlags.GetProperty, null, s, null);Console.WriteLine(needReboot);