HighGuy Posted July 27, 2006 Share Posted July 27, 2006 Hi, I'm looking for a way to determine the system environment variables from a remote computer, f. ex. %Systemroot%. Anyone has an idea how to achieve this? Link to comment Share on other sites More sharing options...
Danny35d Posted July 27, 2006 Share Posted July 27, 2006 I will try to read the registry of the remote computer by using RegRead()\\RemoteComputerName\HKLM\Software\Microsoft\Windows NT\CurrentVersionHere you can get CSDVersion, ProductName, Register Owner, SystemRoot, etc.\\RemoteComputerName\HKLM\System\CurrentControlSet\Control\Session Manager\EnvironmentHere you can find the rest of systems variables AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
HighGuy Posted July 27, 2006 Author Share Posted July 27, 2006 \\RemoteComputerName\HKLM\System\CurrentControlSet\Control\Session Manager\EnvironmentHere you can find the rest of systems variables.. and what do you get there for windir? -> %SystemRoot%. I need something that resolves this to the specific path of the remote windows installation. Not that easy I think Link to comment Share on other sites More sharing options...
Danny35d Posted July 27, 2006 Share Posted July 27, 2006 (edited) .. and what do you get there for windir? -> %SystemRoot%. I need something that resolves this to the specific path of the remote windows installation. Not that easy I thinkDid you look at this RegKey...\\RemoteComputerName\HKLM\Software\Microsoft\Windows NT\CurrentVersionSystemRootYou are right, it not that easy but you can make your script to read both register keys and replace %SystemRoot% for C:\Windows or where ever is the value of the register key above. Edited July 27, 2006 by Danny35d AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
HighGuy Posted July 27, 2006 Author Share Posted July 27, 2006 Did you look at this RegKey...\\RemoteComputerName\HKLM\Software\Microsoft\Windows NT\CurrentVersionSystemRootAh, sorry, missed that one. I only need Systemroot for my current project but thought about creating a universal Function like _RemoteEnvGet(). Thanks a lot for your help! Link to comment Share on other sites More sharing options...
Danny35d Posted July 27, 2006 Share Posted July 27, 2006 Your welcome, glad that I can help.... AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
Danny35d Posted July 28, 2006 Share Posted July 28, 2006 I was bored ... expandcollapse popup$msg = '' $ret = _EnvGet() ; Array with all local environment ;$ret = _EnvGet(-1, 'windir') ; Array with local WINDIR value ;$ret = _EnvGet('ComputerName') ; Array with all remote computer environment ;$ret = _EnvGet('ComputerName', 'Windir') ; Array with remoter computer WINDIR value If IsArray($ret) Then For $x = 1 To $ret[0][0] $msg &= $ret[$x][0] & ' = ' & $ret[$x][1] & @CRLF Next MsgBox(0, 'Environment Variables', $msg) EndIf ;======================================================================================================== ; Function Name: _EnvGet() ; ; Description: Return a two dimensional array with the environment names and values in your system ; or remote system. ; ; Syntax: _EnvGet ( [$s_RemoteComputer, $sEnvGet] ) ; ; Parameter(s): $s_RemoteComputer = Remote ComputerName ; $sEnvGet = Environment variable name ; ; Requirement(s): External: = None. ; Internal: = None. ; ; Return Value(s): On Success: = Returns a two dimensional array with the environment names and values ; sets @error to 0. ; On Failure: = Returns "" and sets @error to 1. ; ; Author(s): Danny35d ; ; Note(s): ; ; Example(s): ; _EnvGetSoftware() it will return a two dimensional array with the environment names and values ; from the local computer ; _EnvGet("ComputerName") it will return a two dimensional array with the environment names and values ; of the remote computer. ; _EnvGet("ComputerName", "EnvGet") it will return a two dimensional array with specific ; environment name and value of the remote computer. ; _EnvGet(-1, "EnvGet") it will return a two dimensional array with specific environment name ; and value of the local computer. ;========================================================================================================== Func _EnvGet($s_RemoteComputer = '', $sEnvGet = '') Local $Count = 0 If $s_RemoteComputer == -1 Then $s_RemoteComputer = '' $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\' $sSystemRoot = RegRead($s_RemoteComputer & 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion', 'SystemRoot') Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' While 1 $Count += 1 $key = RegEnumVal($regkey, $Count) If @error <> 0 then ExitLoop $value = RegRead($regkey, $key) If StringInStr($value, '%SystemRoot%') <> 0 Then $value = StringReplace($value, '%SystemRoot%', $sSystemRoot) If StringLower($sEnvGet) == StringLower($key) Or StringLower($sEnvGet) == 'systemroot' Or ($value <> '' And $sEnvGet == '') Then If Not IsDeclared('avArray') Then Dim $avArray[1] If StringLower($sEnvGet) == 'systemroot' Then ExitLoop ReDim $avArray[UBound($avArray) + 1][2] $avArray[0][0] = UBound($avArray) - 1 $avArray[UBound($avArray) - 1][0] = $key $avArray[UBound($avArray) - 1][1] = $value If StringLower($sEnvGet) == StringLower($key) Then ExitLoop EndIf $value = '' WEnd If Not IsDeclared('avArray') Then SetError(1) Return('') Else If $sEnvGet == '' Or StringLower($sEnvGet) == 'systemroot' Then ReDim $avArray[UBound($avArray) + 1][2] $avArray[0][0] = UBound($avArray) - 1 $avArray[UBound($avArray) - 1][0] = 'SystemRoot' $avArray[UBound($avArray) - 1][1] = $sSystemRoot EndIf SetError(0) Return($avArray) EndIf EndFunc AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line Link to comment Share on other sites More sharing options...
bacobampense Posted August 19, 2010 Share Posted August 19, 2010 Thanks Im glad you were. This is just what i was looking for. I added a gui. #cs= Added GUI. #ce= #include<GUICONSTANTS.AU3> GUICreate("Remote Environment Variables" ,385,200) GUISetBkColor (0x0cc9966) $Remotecomputer_L = GUICtrlCreateLabel ("Enter Remote Host or IP Leave Blanc for Local PC", 10,20,185,30) GUICtrlSetFont(-1,10,200,1, "Arial") $r_Remotecomputer_I = GUICtrlCreateInput ('',200,20,150,30) $EnvGet_L = GUICtrlCreateLabel ("Enter Variable or Leave Blanc for All:", 10,75,185,30) GUICtrlSetFont(-1,10,200,1, "Arial") $r_EnvGet_I = GUICtrlCreateInput ('',200,75,150,30) $s_RemoteComputer = GUICtrlRead($r_Remotecomputer_I) $go_btn = GuiCtrlCreateButton("GO", 100,125,200,30) GuiSetState() While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $go_btn $s_RemoteComputer = GUICtrlRead($r_Remotecomputer_I) $msg = '' $ret = _EnvGet() ; Array with all local environment ;$ret = _EnvGet(-1, 'windir') ; Array with local WINDIR value ;$ret = _EnvGet('ComputerName') ; Array with all remote computer environment ;$ret = _EnvGet('ComputerName', 'Windir') ; Array with remoter computer WINDIR value If IsArray($ret) Then For $x = 1 To $ret[0][0] $msg &= $ret[$x][0] & ' = ' & $ret[$x][1] & @CRLF Next MsgBox(0, 'Environment Variables', $msg) EndIf ExitLoop EndSelect WEnd Exit ;======================================================================================================== ; Function Name: _EnvGet() ; ; Description: Return a two dimensional array with the environment names and values in your system ; or remote system. ; ; Syntax: _EnvGet ( [$s_RemoteComputer, $sEnvGet] ) ; ; Parameter(s): $s_RemoteComputer = remote ComputerName ; $sEnvGet = environment variable name ; ; Requirement(s): External: = None. ; Internal: = None. ; ; Return Value(s): On Success: = Returns a two dimensional array with the environment names and values ; sets @error to 0. ; On Failure: = Returns "" and sets @error to 1. ; ; Author(s): Danny35d ; ; Note(s): ; ; Example(s): ; _EnvGetSoftware() it will return a two dimensional array with the environment names and values ; from the local computer ; _EnvGet("ComputerName") it will return a two dimensional array with the environment names and values ; of the remote computer. ; _EnvGet("ComputerName", "EnvGet") it will return a two dimensional array with specific ; environment name and value of the remote computer. ; _EnvGet(-1, "EnvGet") it will return a two dimensional array with specific environment name ; and value of the local computer. ;========================================================================================================== Func _EnvGet ($s_RemoteComputer = '', $sEnvGet = '') $s_RemoteComputer = GUICtrlRead($r_Remotecomputer_I); $sEnvGet = GUICtrlRead($r_EnvGet_I) Local $Count = 0 If $s_RemoteComputer == -1 Then $s_RemoteComputer = '' $s_RemoteComputer = '\\' & StringReplace($s_RemoteComputer, '\', '') & '\' $sSystemRoot = RegRead($s_RemoteComputer & 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion', 'SystemRoot') Local Const $regkey = $s_RemoteComputer & 'HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' While 1 $Count += 1 $key = RegEnumVal($regkey, $Count) If @error <> 0 then ExitLoop $value = RegRead($regkey, $key) If StringInStr($value, '%SystemRoot%') <> 0 Then $value = StringReplace($value, '%SystemRoot%', $sSystemRoot) If StringLower($sEnvGet) == StringLower($key) Or StringLower($sEnvGet) == 'systemroot' Or ($value <> '' And $sEnvGet == '') Then If Not IsDeclared('avArray') Then Dim $avArray[1] If StringLower($sEnvGet) == 'systemroot' Then ExitLoop ReDim $avArray[uBound($avArray) + 1][2] $avArray[0][0] = UBound($avArray) - 1 $avArray[uBound($avArray) - 1][0] = $key $avArray[uBound($avArray) - 1][1] = $value If StringLower($sEnvGet) == StringLower($key) Then ExitLoop EndIf $value = '' WEnd If Not IsDeclared('avArray') Then SetError(1) Return('') Else If $sEnvGet == '' Or StringLower($sEnvGet) == 'systemroot' Then ReDim $avArray[uBound($avArray) + 1][2] $avArray[0][0] = UBound($avArray) - 1 $avArray[uBound($avArray) - 1][0] = 'SystemRoot' $avArray[uBound($avArray) - 1][1] = $sSystemRoot EndIf SetError(0) Return($avArray) EndIf EndFunc Link to comment Share on other sites More sharing options...
seandisanti Posted August 20, 2010 Share Posted August 20, 2010 Nice! love to see new users applying help and then continuing work instead of just disappearing when they get an answer. One small request though, use the[ autoit] and [/autoit ] tags around code in posts for readability. 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