Darkenor
Darkenor

Reputation: 4449

How can I use WMI to find out the installed Exchange Version using C#?

I would like to be able to query the Exchange version installed on our user's server. I understand that this can be done using WMI, but I'm having a hard time finding a simple explanation using Google. Any advice?

Upvotes: 0

Views: 1999

Answers (2)

Lance U. Matthews
Lance U. Matthews

Reputation: 16606

This should get you started:

string condition = "Vendor LIKE 'Microsoft%' AND Name = 'Exchange'";
string[] selectedProperties = new string[] { "Version" };
SelectQuery query = new SelectQuery("Win32_Product", condition, selectedProperties);

using (ManagementObjectSearcher searcher = new ManagementObjectSearcher(query))
using (ManagementObjectCollection products = searcher.Get())
    foreach (ManagementObject product in products)
    {
        string version = (string) product["Version"];

        // Do something with version...
    }

That searches for instances of the Win32_Product class where the Vendor property begins with "Microsoft" and the Name property is "Exchange", and retrieves the Version property. I don't have access to an installation of Exchange to know what those values will actually be. Even better would be if you can determine what the ProductID property would be for Exchange so you can filter just based on that.

Note that not all installed applications are returned by Win32_Product (it seems to be mostly Microsoft applications and those with Windows Installer installers). So, for all I know Exchange is not one of these applications!

Upvotes: 1

Afshin
Afshin

Reputation: 1253

I also have the same question: Exchange (server) on user's computer? btw, here you can find a good sample source with explanations of how to retrieve list of installed applications on (any) windows pc, using WMI.

The idea behind this is using "SELECT * FROM Win32_Product" query from "\root\cimv2" to select list of applications.

each application item (implemented class) has it's own 'IdentifyingNumber', 'Description', 'Version', etc. which help you find your answer.

Upvotes: 0

Related Questions