Sign in to follow this  
Followers 0
HighGuy

Determine remote environment variables

9 posts in this topic

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?

Share this post


Link to post
Share on other sites



I will try to read the registry of the remote computer by using RegRead()

\\RemoteComputerName\HKLM\Software\Microsoft\Windows NT\CurrentVersion

Here you can get CSDVersion, ProductName, Register Owner, SystemRoot, etc.

\\RemoteComputerName\HKLM\System\CurrentControlSet\Control\Session Manager\Environment

Here you can find the rest of systems variables


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

\\RemoteComputerName\HKLM\System\CurrentControlSet\Control\Session Manager\Environment

Here 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 :whistle:

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 think

Did you look at this RegKey...

\\RemoteComputerName\HKLM\Software\Microsoft\Windows NT\CurrentVersion

SystemRoot

You 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 by Danny35d

AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

Did you look at this RegKey...

\\RemoteComputerName\HKLM\Software\Microsoft\Windows NT\CurrentVersion

SystemRoot

Ah, 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!

Share this post


Link to post
Share on other sites

Your welcome, glad that I can help.... :whistle:


AutoIt Scripts:NetPrinter - Network Printer UtilityRobocopyGUI - GUI interface for M$ robocopy command line

Share this post


Link to post
Share on other sites

I was bored ...

$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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0