Jump to content


This is a ready-only archive of the InstallSite Forum. You cannot post any new content here. / Dies ist ein Archiv des InstallSite Forums. Hier können keine neuen Beiträge veröffentlicht werden.
Photo

MSI API example for detecting a Windows Hotfix


1 reply to this topic

deramor

deramor
  • Full Members
  • 187 posts

Posted 01 December 2015 - 00:46

All-

 

I am trying to write a custom action in a c++ dll that can detect the presence of a specific Windows 7 Hotfix.

 

I am using MsiEnumProducts and able to cycle through all the installed products.  It appears to work but it does not include Windows itself in the available products.

 

Does anyone know how I can enumerate installed windows hotfixes/patches/KBs using the MSI API?



deramor

deramor
  • Full Members
  • 187 posts

Posted 01 December 2015 - 21:49

I found a Microsoft API called WUApi (Windows Update Agent API)

 

It is a COM library (WUApiLib). 

https://msdn.microso...y/aa387101.aspx

 

I wrote a proof of concept C# console app just to see if it works.  I have mixed results.

 

The code:

using System;
using System.Collections.Generic;
using System.Text;
using WUApiLib;

namespace WUApiExample
{
    class Program
    {
        static void Main(string[] args)
        {
            UpdateSession uSession = new UpdateSession();
            IUpdateSearcher uSearcher = uSession.CreateUpdateSearcher();

            uSearcher.Online = false;
            try
            {
                ISearchResult sResult = uSearcher.Search("IsInstalled=1 and Type='Software' and IsHidden=0");
                Console.WriteLine( "Found " + sResult.Updates.Count + " updates" + Environment.NewLine);
                foreach (IUpdate update in sResult.Updates)
                {
                    Console.WriteLine(update.Title + Environment.NewLine);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Something went wrong: " + ex.Message);
            }
            Console.ReadLine();

        }
    }
}

The above code always returns 2 results.

 

The Search Parameters "IsInstalled=1 and Type='Software' and IsHidden=0" can be changed to modify the results but the most I have ever had were 2 hits.

 

I have even gone so far as to change the search parameters to "IsInstalled=1" or simply "Type='Software'"

 

Does anyone have experience with this API?  What am I doing wrong?