简体   繁体   English

如何使用WMI通过C#找出已安装的Exchange版本?

[英]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. 我希望能够查询安装在我们用户服务器上的Exchange版本。 I understand that this can be done using WMI, but I'm having a hard time finding a simple explanation using Google. 我知道可以使用WMI来完成此操作,但是使用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. 这将搜索Win32_Product类的实例,其中Vendor属性以"Microsoft"开头,并且Name属性为"Exchange" ,并检索Version属性。 I don't have access to an installation of Exchange to know what those values will actually be. 我没有安装Exchange的权限,无法知道这些值实际上是什么。 Even better would be if you can determine what the ProductID property would be for Exchange so you can filter just based on that. 更好的是,如果您可以确定Exchange的ProductID属性是什么,以便可以仅基于此进行过滤。

Note that not all installed applications are returned by Win32_Product (it seems to be mostly Microsoft applications and those with Windows Installer installers). 请注意,并非所有已安装的应用程序都由Win32_Product返回(它似乎主要是Microsoft应用程序以及带有Windows Installer安装程序的应用程序)。 So, for all I know Exchange is not one of these applications! 因此,就我所知,Exchange不是这些应用程序之一!

I also have the same question: Exchange (server) on user's computer? 我也有同样的问题:用户计算机上的Exchange(服务器)? 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. 顺便说一句, 在这里您可以找到一个很好的示例源,其中包含有关如何使用WMI检索(任何)Windows PC上已安装应用程序列表的说明。

The idea behind this is using "SELECT * FROM Win32_Product" query from "\\root\\cimv2" to select list of applications. 其背后的思想是使用“ \\ root \\ cimv2”中的“ SELECT * FROM Win32_Product”查询来选择应用程序列表。

each application item (implemented class) has it's own 'IdentifyingNumber', 'Description', 'Version', etc. which help you find your answer. 每个应用程序项(实现的类)都有自己的'IdentifyingNumber','Description','Version'等,可帮助您找到答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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