【问题标题】:Retrieve Windows Update history using WUAPILib from a remote machine使用 WUAPILib 从远程计算机检索 Windows 更新历史记录
【发布时间】:2013-03-25 01:21:47
【问题描述】:

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

根据微软Using WUA From a Remote Computer的文章可能的:

“Windows 更新代理 (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));
}    

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

【问题讨论】:

    标签: c# windows-update


    【解决方案1】:

    related question的回答基本回答了我的问题。

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

    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));
    }
    

    【讨论】:

      猜你喜欢
      • 2013-04-25
      • 2018-08-22
      • 2019-10-28
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      相关资源
      最近更新 更多