使用 C# 确定系统上 Exchange 服务器的版本

发布于 2024-10-02 09:10:49 字数 58 浏览 0 评论 0原文

有没有办法通过 C# 检测正在运行的 Exchange Server 版本(2007 或 2010)?

Is there a way to detect which version of Exchange Server is running (2007 or 2010) via c#?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别再吹冷风 2024-10-09 09:10:49

这里有 VBScript使用 WMI 和 AD 获取域中所有 Exchange 服务器的版本。如果它不能按原样使用,您可以将此逻辑转换为适当的 .Net 类。

'****************************************************************************
' This script created by Chrissy LeMaire ([email protected])
' Website: http://netnerds.net/
'
' This script finds all Exchange Servers in AD. Includes Exchange Version.
'
' Run this script with admin privs on any computer within a domain.
'
' This script has only been tested on Windows Server 2003
'
' NO WARRANTIES, USE THIS AT YOUR OWN RISK, etc.
'*****************************************************************************

Set objAdRootDSE = GetObject("LDAP://RootDSE")
Set objRS = CreateObject("adodb.recordset")

varConfigNC = objAdRootDSE.Get("configurationNamingContext")

  strConnstring = "Provider=ADsDSOObject"
  strSQL = "SELECT * FROM 'LDAP://" & varConfigNC & "' WHERE objectCategory='msExchExchangeServer'"
  objRS.Open strSQL, strConnstring
    Do until objRS.eof
Set objServer = GetObject(objRS.Fields.Item(0))
    Call getExchangeInfo(objServer.CN)
Set objServer = Nothing
        objRS.movenext
    Loop
  objRS.close

Set objRS = Nothing
Set objAdRootDSE = Nothing

Sub getExchangeInfo(strServerName)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strServerName & "\\ROOT\MicrosoftExchangeV2")
Set colItems = objWMIService.ExecQuery("Select * from Exchange_Server")

For Each objItem in colItems
MsgBox UCase(objItem.Name) & " (" & objItem.FQDN & ") is running Exchange " & objItem.ExchangeVersion
Next

Set colItems = Nothing
Set objWMIService = Nothing
End Sub

There is VBScript here that gets the version for all Exchange Servers in the domain using WMI and AD. You could convert this logic to the appropriate .Net classes if this is not usable as is.

'****************************************************************************
' This script created by Chrissy LeMaire ([email protected])
' Website: http://netnerds.net/
'
' This script finds all Exchange Servers in AD. Includes Exchange Version.
'
' Run this script with admin privs on any computer within a domain.
'
' This script has only been tested on Windows Server 2003
'
' NO WARRANTIES, USE THIS AT YOUR OWN RISK, etc.
'*****************************************************************************

Set objAdRootDSE = GetObject("LDAP://RootDSE")
Set objRS = CreateObject("adodb.recordset")

varConfigNC = objAdRootDSE.Get("configurationNamingContext")

  strConnstring = "Provider=ADsDSOObject"
  strSQL = "SELECT * FROM 'LDAP://" & varConfigNC & "' WHERE objectCategory='msExchExchangeServer'"
  objRS.Open strSQL, strConnstring
    Do until objRS.eof
Set objServer = GetObject(objRS.Fields.Item(0))
    Call getExchangeInfo(objServer.CN)
Set objServer = Nothing
        objRS.movenext
    Loop
  objRS.close

Set objRS = Nothing
Set objAdRootDSE = Nothing

Sub getExchangeInfo(strServerName)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!" & strServerName & "\\ROOT\MicrosoftExchangeV2")
Set colItems = objWMIService.ExecQuery("Select * from Exchange_Server")

For Each objItem in colItems
MsgBox UCase(objItem.Name) & " (" & objItem.FQDN & ") is running Exchange " & objItem.ExchangeVersion
Next

Set colItems = Nothing
Set objWMIService = Nothing
End Sub
伤痕我心 2024-10-09 09:10:49

您最好的选择是使用 WMI

Your best bet would be to use WMI

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文