简体   繁体   中英

Retrieve Windows Update history using WUAPILib from a remote machine

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 possible according to Microsoft's article Using WUA From a Remote Computer : 使用WUA从远程计算机

"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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM