Use C# to interact with Windows Update

Add a Reference to WUApiLib to your C# project.

using WUApiLib;
protected override void OnLoad(EventArgs e){
    base.OnLoad(e);
    UpdateSession uSession = new UpdateSession();
    IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();
    uSearcher.Online = false;
    try {
        ISearchResult sResult = uSearcher.Search("IsInstalled=1 And IsHidden=0");
        textBox1.Text = "Found " + sResult.Updates.Count + " updates" + Environment.NewLine;
        foreach (IUpdate update in sResult.Updates) {
                textBox1.AppendText(update.Title + Environment.NewLine);
        }
    }
    catch (Exception ex) {
        Console.WriteLine("Something went wrong: " + ex.Message);
    }
}

Given you have a form with a TextBox this will give you a list of the currently installed updates. See http://msdn.microsoft.com/en-us/library/aa387102(VS.85).aspx for more documentation.

This will, however, not allow you to find KB hotfixes which are not distributed via Windows Update.

Leave a Comment