lostangel556 Posted May 3, 2009 Share Posted May 3, 2009 Hi Everyone, I've written an function to remotely check what version of exchange server is running on an server. However, for some reason it doesn't seem to want to read the Dword value. I've tried RegRead() aswell but that produces the same result and im running the script as an domain admin. Any Ideas? CODEFunc _DetectExchangeVersion($strExchangeServer) Const $HKEY_LOCAL_MACHINE = Hex("0x80000002") Dim $dwValue $strValueName = "NewestBuild" $strKeyPath = "SOFTWARE\Microsoft\Exchange\Setup" If @ComputerName = $strExchangeServer Then $dwValue = RegRead("HKLM\" & $strKeyPath, $strValueName) Else $objWMI = ObjGet("winmgmts:\\" & $strExchangeServer & "\root\default") $objRegistry = $objWMI.Get("StdRegProv") $objRegistry.GetDWORDValue($HKEY_LOCAL_MACHINE,$strKeyPath,$strValueName, $dwValue) EndIf MsgBox(0,"",$dwValue) Select Case $dwValue > 6944 AND $dwValue < 9999 MsgBox(0,"","2003") Case $dwValue > 9999 MsgBox(0,"","2007") Case $dwValue < 6944 AND $dwValue < "" MsgBox(0,"","2000") EndSelect EndFunc Link to comment Share on other sites More sharing options...
lostangel556 Posted May 3, 2009 Author Share Posted May 3, 2009 Forgot to mention that when i do the script in vbscript, it works without problem, but cant figure out how to pass the value back to autoit CODEConst HKEY_LOCAL_MACHINE = &H80000002 strComputer = 'Exchange server to test Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv") strValueName = "NewestBuild" strKeyPath = "SOFTWARE\Microsoft\Exchange\Setup" objRegistry.GetDWORDValue HKEY_LOCAL_MACHINE,strKeyPath,strValueName,dwValue If dwValue > 6944 AND dwValue < 9999 Then Wscript.Echo "2003" If dwValue > 9999 Then Wscript.Echo "2007" If dwValue < 6944Then Wscript.Echo "2000" Link to comment Share on other sites More sharing options...
Zinthose Posted May 4, 2009 Share Posted May 4, 2009 (edited) This may not apply but:If this is a 32 bit version of the exchange server running on a 64 bit windows server then the strKeyPath is "SOFTWARE\WoW6432Node\Microsoft\Exchange\Setup" and not "SOFTWARE\Microsoft\Exchange\Setup"Otherwise, Check this out.$Build = _DetectExchangeVersion() MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Build' & @lf & @lf & 'Return:' & @lf & $Build) ;### Debug MSGBOX Func _DetectExchangeVersion($strExchangeServer = @ComputerName) Local Const $strValueName = "NewestBuild" Local $strKeyName = "\\\\%s\\HKLM\\SOFTWARE\\Microsoft\\Exchange\\Setup" Local $dwValue = 0 ;## Encode KeyName $strKeyName = StringFormat($strKeyName, $strExchangeServer) ;## Read registry value from remote server $dwValue = RegRead($strKeyName, $strValueName) If @error Then Return SetError(1, @error, -1) ;## Test returned value for know build ranges Switch $dwValue Case 0, 4417 To 6603 Return "2000" Case 6944 To 7638 Return "2003" Case 685, 10240 ;To 11000; <== This will need updated as new versions are released. Return "2007" Case Else Return "Unknown Build: " & $dwValue EndSwitch EndFunc Corrected "WoW64" to "WoW6432Node" Edited May 4, 2009 by Zinthose --- TTFN Link to comment Share on other sites More sharing options...
lostangel556 Posted May 4, 2009 Author Share Posted May 4, 2009 Many thanks but would you believe it i found an answer aswell If the regread on \\HKLM\SOFTWARE\Microsoft\Exchange\Setup\NewestBuild returns an blank then it must be an 64 bit registry (which complies with exchange 2007) so i tell it to regread \\HKLM64\SOFTWARE\Microsoft\Exchange\Setup\NewestBuild This returns the value then i can do the select statement to determine its version Thanks for your suggestion though. i May use yours instead depending on the run speed of the 2 scripts This may not apply but: If this is a 32 bit version of the exchange server running on a 64 bit windows server then the strKeyPath is "SOFTWARE\WoW6432Node\Microsoft\Exchange\Setup" and not "SOFTWARE\Microsoft\Exchange\Setup" Otherwise, Check this out. $Build = _DetectExchangeVersion() MsgBox(262144,'Debug line ~' & @ScriptLineNumber,'Selection:' & @lf & '$Build' & @lf & @lf & 'Return:' & @lf & $Build) ;### Debug MSGBOX Func _DetectExchangeVersion($strExchangeServer = @ComputerName) Local Const $strValueName = "NewestBuild" Local $strKeyName = "\\\\%s\\HKLM\\SOFTWARE\\Microsoft\\Exchange\\Setup" Local $dwValue = 0 ;## Encode KeyName $strKeyName = StringFormat($strKeyName, $strExchangeServer) ;## Read registry value from remote server $dwValue = RegRead($strKeyName, $strValueName) If @error Then Return SetError(1, @error, -1) ;## Test returned value for know build ranges Switch $dwValue Case 0, 4417 To 6603 Return "2000" Case 6944 To 7638 Return "2003" Case 685, 10240 ;To 11000; <== This will need updated as new versions are released. Return "2007" Case Else Return "Unknown Build: " & $dwValue EndSwitch EndFunc Corrected "WoW64" to "WoW6432Node" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now