Travis Posted October 11, 2020 Share Posted October 11, 2020 I am on WIndows 10. If you have a system and user environment variable of the same name, in my case, PATH, when calling EnvGet("PATH") The return is the system PATH with the user PATH at the end. No indicator of which ends where. Is it not possible to specify the scope of the variable I am trying to access? Link to comment Share on other sites More sharing options...
abberration Posted October 11, 2020 Share Posted October 11, 2020 Would this help? #include <Array.au3> #include <String.au3> $aEnv = StringSplit(EnvGet("PATH"), ";") _ArrayDisplay($aEnv) Easy MP3 | Software Installer | Password Manager Link to comment Share on other sites More sharing options...
TheXman Posted October 11, 2020 Share Posted October 11, 2020 (edited) 1 hour ago, Travis said: Is it not possible to specify the scope of the variable I am trying to access? You can query the current user's environment variables or the system's environment variables by reading the appropriate registry key: HKEY_CURRENT_USER\Environment HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment Example: $sRegValue = RegRead("HKEY_CURRENT_USER\Environment", "Path") ConsoleWrite("Current User:" & @CRLF & $sRegValue & @CRLF) $sRegValue = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "Path") ConsoleWrite("System:" & @CRLF & $sRegValue & @CRLF) Edited October 11, 2020 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
Subz Posted October 11, 2020 Share Posted October 11, 2020 Here is part of a environment variable udf that I started working on. expandcollapse popupConsoleWrite("System Path = " & _EnvVarGet("Path", 2) & @CRLF & @CRLF) ConsoleWrite("User Path = " & _EnvVarGet("Path", 3) & @CRLF & @CRLF) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _EnvVarGet ; Description ...: Get Environment Variables ; Syntax ........: _EnvVarGet($_sEnvVarGet[, $_iEnvVarType = 3[, $_bExpVarValue = False]]) ; Parameters ....: $_sEnvVarGet - Environment variable name ; : $_iEnvVarType - [optional] Environment variable type. Default is 3. ; : - 0 - Returns Enviroment variable from all profile types ; : - 1 - Process Enviornment Variable ; : - 2 - System Enviornment Variable ; : - 3 - User Enviornment Variable (default) ; : - 4 - Volatile Enviornment Variable ; : $_bExpVarValue - [optional] Expand Environment Variables within result. Default is False. ; Return values .: ; : Flag: $_iEnvVarType ; : - 0 - Returns Enviroment variable from all profile types as an array ; : - 1 - Process Enviornment Variable as a string ; : - 2 - System Enviornment Variable as a string ; : - 3 - User Enviornment Variable as a string ; : - 4 - Volatile Enviornment Variable as a string ; Author ........: Subz ; Modified ......: ; Remarks .......: ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _EnvVarGet($_sEnvVarGet, $_iEnvVarType = 3, $_bExpVarValue = False) Local $iExpandEnvStrings = Opt("ExpandEnvStrings") Local $sEnvVarValue, $aEnvVarValue[5] = [4] Local $oEnvVarType, $aEnvVarType[5] = [4, "PROCESS", "SYSTEM", "USER", "VOLATILE"] Local $oWshShell = ObjCreate("WScript.Shell") Switch $_iEnvVarType Case 0 If $_bExpVarValue == True Then Opt("ExpandEnvStrings", 1) For $i = 1 To $aEnvVarType[0] $oEnvVarType = $oWshShell.Environment($aEnvVarType[$i]) $aEnvVarValue[$i] = $oEnvVarType($_sEnvVarGet) Next Opt("ExpandEnvStrings", $iExpandEnvStrings) Return $aEnvVarValue Case 1 To 4 If $_bExpVarValue == True Then Opt("ExpandEnvStrings", 1) $oEnvVarType = $oWshShell.Environment($aEnvVarType[$_iEnvVarType]) $sEnvVarValue = $oEnvVarType($_sEnvVarGet) Opt("ExpandEnvStrings", $iExpandEnvStrings) Return $sEnvVarValue Case Else Return SetError(1, 0, "") EndSwitch EndFunc sylremo 1 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