Jump to content

Set Windows System variables w/ Auto it


Recommended Posts

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

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

 

Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...