;; ;;=====================================================================================----- ;; ;;FUNCTION fSetM() / fGetM() ;; ;;ACTION fSetM: Sets/Gets an environment var on the local or target server ;; ;;AUTHOR Glenn Barnas ;; ;;VERSION 1.0 - 2002/06/11 ;; ;;HISTORY 1.0 - 2002/06/11 - Initial Release ;; ;;SYNTAX fSetM: fSetM(Var=Value [, server]) fGetM: $VAR = fGetM(Value [, server]) ;; ;;PARAMETERS fSetM: Value - Value to define, in the format "VARNAME=value" ;; fGetM: Value - name of environment var to retrieve ;; ;;REMARKS fGetM always reads from the registry, not the local environment ;; ;;RETURNS fSetM: Value of @ERROR fGetM: Value of environment variable ;; ;;DEPENDENCIES None ;; ;;EXAMPLES $Path = fGetM("PATH") ;; fSetM("PATH=c:\temp;" + $Path, "system2") ; Function fSetM($_EDEF, OPTIONAL $_Target) Dim $_fENVKEY, $_aryENVARGS $_Target = IIf(CStr($_Target) <> '', '\\' + Join(Split(CStr($_Target), '\'), '', 3) + '\', '') If $_Target = '' SetM($_EDEF) ; use local SETM command Exit @ERROR Else $_fENVKEY = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' $_aryENVARGS = Split($_EDEF, '=', 2) ; If the data is null, remove the key, otherwise write the data/value to the key If $_aryENVARGS[1] = '' $fSetM = DelValue($_Target + $_fENVKEY, $_aryENVARGS[0]) Exit @ERROR Else $fSetM = WriteValue($_Target + $_fENVKEY, $_aryENVARGS[0], $_aryENVARGS[1], 'REG_EXPAND_SZ') Exit @ERROR EndIf EndIf EndFunction ; read directly from the registry Function fGetM($_EDEF, OPTIONAL $_Target) Dim $_fENVKEY $_Target = IIf(CStr($_Target) <> '', '\\' + Join(Split(CStr($_Target), '\'), '', 3) + '\', '') $_fENVKEY = 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment' $fGetM = ReadValue($_Target + $_fENVKEY, $_EDEF) Exit @ERROR EndFunction