Salvador
Salvador

Reputation: 16472

How can programmatically check which version of the WMI is installed

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

Upvotes: 3

Views: 796

Answers (1)

cpalmer
cpalmer

Reputation: 1117

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"]);

Upvotes: 5

Related Questions