Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a list of installed updates and hotfixes?

A list of every update and hotfix that has been installed on my computer, coming from either Microsoft Windows Update or from the knowledge base. I need the ID of each in the form of KBxxxxxx or some similar representation...

Currently I have:

const string query = "SELECT HotFixID FROM Win32_QuickFixEngineering";
var search = new ManagementObjectSearcher(query);
var collection = search.Get();

foreach (ManagementObject quickFix in collection)
    Console.WriteLine(quickFix["HotFixID"].ToString());

But this does not seem to list everything, it only lists QFE's.

I need it to work on Windows XP, Vista and 7.

like image 363
Tamara Wijsman Avatar asked May 02 '09 18:05

Tamara Wijsman


1 Answers

After some further search on what I've found earlier. (Yes, the same as VolkerK suggests first)

  1. Under VS2008 CMD in %SystemRoot%\System32\ run a command to get a managed dll:
    tlbimp.exe wuapi.dll /out=WUApiInterop.dll
  2. Add WUApiInterop.dll as a project reference so we see the functions.

Using the following code I can get a list from which I can extract the KB numbers:

var updateSession = new UpdateSession();
var updateSearcher = updateSession.CreateUpdateSearcher();
var count = updateSearcher.GetTotalHistoryCount();
var history = updateSearcher.QueryHistory(0, count);

for (int i = 0; i < count; ++i)
    Console.WriteLine(history[i].Title);
like image 198
Tamara Wijsman Avatar answered Sep 20 '22 15:09

Tamara Wijsman