从远程计算机使用WUAPILib检索Windows Update历史记录

Bos*_*sco 3 c# windows-update

是否可以使用WUAPI 2.0类型库在远程计算机上查看Windows Update历史记录?它必须与Windows XP和Windows 7计算机兼容.

根据微软的文章可以使用WUA从远程计算机:

"Windows Update代理(WUA)API可供远程计算机上的用户使用,也可由远程计算机上运行的应用程序使用."

...但我无法找到解释如何实际查询远程机器或在何处指定机器主机名或IP地址的任何地方.

我使用以下示例代码从本地计算机获取我需要的信息:

UpdateSession updateSession = new UpdateSession();
IUpdateSearcher updateSearcher = updateSession.CreateUpdateSearcher();
int count = updateSearcher.GetTotalHistoryCount();
IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count);
for (int i = 0; i < count; ++i)
{
     Console.WriteLine(string.Format("Title: {0}\tSupportURL: {1}\tDate: {2}\tResult Code: {3}\tDescription: {4}\r\n", history[i].Title, history[i].SupportUrl, history[i].Date, history[i].ResultCode, history[i].Description));
}    
Run Code Online (Sandbox Code Playgroud)

是否可以使用WUAPILib(或类似的)从远程机器中提取与上述代码相同的信息?WMI类Win32_QuickFixEngineering不提供与WUAPILib相同的信息,因此它不是一个选项,我宁愿不必手动挖掘注册表来提取信息.谢谢!

Bos*_*sco 7

相关问题的答案基本上回答了我的问题.

下面修改后的代码示例现在可以查询远程机器:

Type t = Type.GetTypeFromProgID("Microsoft.Update.Session", "remotehostname");
UpdateSession session = (UpdateSession)Activator.CreateInstance(t);
IUpdateSearcher updateSearcher = session.CreateUpdateSearcher();
int count = updateSearcher.GetTotalHistoryCount();
IUpdateHistoryEntryCollection history = updateSearcher.QueryHistory(0, count);
for (int i = 0; i < count; ++i)
{
    Console.WriteLine(string.Format("Title: {0}\tSupportURL: {1}\tDate: {2}\tResult Code: {3}\tDescription: {4}\r\n", history[i].Title, history[i].SupportUrl, history[i].Date, history[i].ResultCode, history[i].Description));
}
Run Code Online (Sandbox Code Playgroud)