Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am looking for a C# / WMI solution to find the version of Exchange server installed in a machine.

I have used the following query and it is not responding.
C#
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...
}


The execution control goes somewhere when we debug the code, exactly when we reach the loop, see the underlined code.

Can anyone help me to solve this?

What would be the WMI query to find the version of Exchange server?
Thanking You...
Posted
Updated 7-May-13 3:09am
v3

1 solution

Try wrapping "string version = (string)product["Version"];" in a try/catch - could be that there are some objects that don't have a version - and that could cause the execution control to go haywire...
 
Share this answer
 
v3
Comments
Sebastian T Xavier 8-May-13 1:08am    
Thank you for this update. Do you know any WMI method to know the version of Exchange server?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900