Sign in to follow this  
Followers 0
Bagjan Wiedus

Using EnvUpdate

7 posts in this topic

Gentlepeople,

I read the following about EnvSet in the online docs:

A environment variable set in this way will only be accessible to programs that AutoIt spawns (Run, RunWait). Once AutoIt closes, the variables will cease to exist.

When I run EnvUpdate after an EnvSet will the variable exists after a reboot?

Kind regards,

Jan Souman

Share this post


Link to post
Share on other sites



I could be wrong but I think the answer is no.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Gentlepeople,

I read the following about EnvSet in the online docs:

A environment variable set in this way will only be accessible to programs that AutoIt spawns (Run, RunWait). Once AutoIt closes, the variables will cease to exist.

When I run EnvUpdate after an EnvSet will the variable exists after a reboot?

Kind regards,

Jan Souman

Nothing to do with permanent setting. the EnvUpdate is to be used inside the script. I am not sure I can explain when it is usefull

the following code prove it is not needed for program launch inside the script. You can verify that the variable is not permanent. I don't know if there is a slight error in the doc

Opt("ExpandEnvStrings",1)
Run(@ComSpec & " /k set testjpm")
$result="prev=%tesjpm%"
EnvSet("testjpm","Jean-Paul")
$result&=" set=%testjpm%"
Run(@ComSpec & " /k set testjpm")
EnvUpdate()
$result&=" update=%testjpm%"
Run(@ComSpec & " /k set testjpm")
MsgBox(0,"Results",$result)
:whistle: Edited by jpm

Share this post


Link to post
Share on other sites

Nothing to do with permanent setting. the EnvUpdate is to be used inside the script. I am not sure I can explain when it is usefull

the following code prove it is not needed for program launch inside the script. You can verify that the variable is not permanent. I don't know if there is a slight error in the doc

Opt("ExpandEnvStrings",1)
Run(@ComSpec & " /k set testjpm")
$result="prev=%tesjpm%"
EnvSet("testjpm","Jean-Paul")
$result&=" set=%testjpm%"
Run(@ComSpec & " /k set testjpm")
EnvUpdate()
$result&=" update=%testjpm%"
Run(@ComSpec & " /k set testjpm")
MsgBox(0,"Results",$result)
:whistle:
Ok so it seems it is not working but how can I set the environment variables permanently?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Ok so it seems it is not working but how can I set the environment variables permanently?

RegWrite ( 'HKEY_CURRENT_USER\Environment', 'UserType', 'REG_SZ', $UserType )

or for all session

RegWrite ( 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment','UserType', 'REG_SZ', $UserType )

perhaps the EnvUpdate() is need after to refresh the environment working inside the running script

Edit a typo in all session

Edited by jpm

Share this post


Link to post
Share on other sites

RegWrite ( 'HKEY_CURRENT_USER\Environment', 'UserType', 'REG_SZ', $UserType )

or for all session

RegWrite ( 'HKEYHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment','UserType', 'REG_SZ', $UserType )

perhaps the EnvUpdate() is need after to refresh the environment working inside the running script

Thanks I will try if this works!

Share this post


Link to post
Share on other sites

UDF at bottom of page to add environmental variable in registry.

http://www.autoitscript.com/forum/index.ph...ental++variable

EnvGet and EnvSet is used during the current scripts operation. EnvUpdate has little to do with EnvGet or EnvSet operation in the script.

EnvUpdate is used to refresh the environmental variables in the registry so you do not need to reboot but is only available to the following script execution, not the current script.

Hmm, hope I explained that right. :whistle:

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