简体   繁体   中英

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?

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!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM