Retrieve Windows Update history using WUAPILib from a remote machine

Bosco picture Bosco · Apr 3, 2013 · Viewed 8.4k times · Source

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!

Answer

Bosco picture Bosco · Apr 3, 2013

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