Retrieve Windows Update history using WUAPILib from a remote machine

依然范特西╮ 提交于 2019-12-13 14:21:11

问题


Is it possible to view Windows Update history on a remote machine using the WUAPI 2.0 Type Library? It must be compatible with both Windows XP and Windows 7 machines.

It is possible according to Microsoft's article Using WUA From a Remote Computer:

"The Windows Update Agent (WUA) API can be used by a user on a remote computer or by an application that is running on a remote computer."

...but I cannot find anywhere that explains how to actually query a remote machine or where to specify a machine hostname or IP address.

I am using the following sample code to get the information I require from the local machine:

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

Is it possible to use WUAPILib (or similar) to pull back the same information as the above code from a remote machine? The WMI class Win32_QuickFixEngineering does not supply the same information as WUAPILib so it is not an option and I'd prefer to not have to manually dig through the registry to extract the information. Thank you!


回答1:


The answer of a related question basically answered my question.

The modified code sample below can now query remote machines:

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


来源:https://stackoverflow.com/questions/15786294/retrieve-windows-update-history-using-wuapilib-from-a-remote-machine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!