Determining version of Exchange server on the system using C#

笑着哭i 提交于 2019-12-30 10:36:03

问题


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


回答1:


Your best bet would be to use WMI




回答2:


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 (clemaire@gmail.com)
' 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


来源:https://stackoverflow.com/questions/4197440/determining-version-of-exchange-server-on-the-system-using-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!