tags:

views:

138

answers:

1

How can programmatically check wich version of the WMI (Windows Management Instrumentation) is installed using delphi or C# ?

thanks in advance.

+4  A: 

Try:

        using System.Management;

        ManagementObjectSearcher query = new
            ManagementObjectSearcher("SELECT * FROM Win32_WMISetting") ;
        ManagementObjectCollection items = query.Get();
        foreach (ManagementObject mo in items)
        {
            System.Console.WriteLine(mo["BuildVersion"]);
        }

There should only be one thing in the items collection since that setting is a singleton. "BuildVersion" is the WMI version that is installed.

EDIT:

Helen's comment below gives an even more succinct solution:

System.Console.WriteLine(
       (new ManagementObject("Win32_WMISetting=@"))["BuildVersion"]);
cpalmer
+1 the `Win32_WMISetting` class retrieves the info about the version of the WMI.
RRUZ
Since `Win32_WMISetting` is a singleton, you can simply use `(new ManagementObject("Win32_WMISetting=@"))["BuildVersion"]`.
Helen