KDoc Posted May 14, 2019 Share Posted May 14, 2019 Hi, Is there any way to set or modify a Windows System Environment variable with Auto it? I don't know if it is possible to change a windows environment system variable and then access the windows system variable from an external program. Thanks Link to comment Share on other sites More sharing options...
Earthshine Posted May 14, 2019 Share Posted May 14, 2019 Why don’t you try it and find out? Then post your code if you’re having problems My resources are limited. You must ask the right questions Link to comment Share on other sites More sharing options...
Exit Posted May 14, 2019 Share Posted May 14, 2019 (edited) See envset() in the help file. To set the environment variables permanently, the command 'SETX' must be used. System variables require Admin privilege. Edited May 14, 2019 by Exit App: Au3toCmd UDF: _SingleScript() Link to comment Share on other sites More sharing options...
Subz Posted May 14, 2019 Share Posted May 14, 2019 See post below with regards to envset(), however you can use either EnvUpdate or WScript.Shell method: Or use WScript.Shell (I actually wrote this yesterday for a project I'm on, so has limited testing). ;~ $_iEnvType = 0 - Sets Enviroment Variable for all profiles ;~ $_iEnvType = 1 = Set Process Enviornment Variable ;~ $_iEnvType = 2 = Set System Enviornment Variable ;~ $_iEnvType = 3 = Set User Enviornment Variable ;~ $_iEnvType = 4 = Set Volatile Enviornment Variable Func _EnvVarSet($_sEnvVarName = "", $_sEnvVarValue = "", $_iEnvVarType = 3) Local $oEnvVarType, $aEnvVarType[5] = [4, "PROCESS", "SYSTEM", "USER", "VOLATILE"] Local $oWshShell = ObjCreate("WScript.Shell") Switch $_iEnvVarType Case 0 For $i = 1 To $aEnvVarType[0] $oEnvVarType = $oWshShell.Environment($aEnvVarType[$i]) $oEnvVarType($_sEnvVarName) = $_sEnvVarValue Next Case 1 To 4 $oEnvVarType = $oWshShell.Environment($aEnvVarType[$_iEnvVarType]) $oEnvVarType($_sEnvVarName) = $_sEnvVarValue Case Else Return SetError(1) EndSwitch EndFunc Exit 1 Link to comment Share on other sites More sharing options...
KDoc Posted May 17, 2019 Author Share Posted May 17, 2019 Hi Subz, That worked perfectly!! Vow. Can't tell you how much I appreciate this. I have been trying to find this solution for months and yours is the only one that actually worked! K 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