Jump to content
Sign in to follow this  
ocryan

Registry changes with EnvUpdate

Recommended Posts

ocryan

Hey everyone,

I'm new to AutoIt and this forum, and am using it to do some very basic things that would be a complete pain in the @#$ with batch.

Here's my code, but it seems that the environment variables I'm writing aren't registering. They show up when I go to the Environment Variables in System Properties correctly, but when I call them in my batch scripts after setting them with this little script, they don't work. I had read somewhere that EnvUpdate WILL work for registry changes, and this is a registry change, so I'm a little perplexed why this isn't working. I can't do a restart in the middle of my scripts, I need some way to set environment variables and then be able to read them almost instantly after this script below has run.

RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "CATALINA_HOME" , "REG_SZ" , "C:\apache-tomcat-5.5.27")
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "DERBY_INSTALL" , "REG_SZ" , "C:\db-derby-10.4.2.0-bin")
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "JRE_HOME" , "REG_SZ" , "C:\Program Files\Java\jre1.5.0_05")
RegWrite("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "JAVA_HOME" , "REG_SZ" , "C:\Program Files\Java\jdk1.5.0_05")

EnvUpdate( )

Thanks!

OCRyan

Share this post


Link to post
Share on other sites
ZeeMars

Nobody give answer?

i aslo want to know this

Share this post


Link to post
Share on other sites
MHz

You can write the environmental variables to registry and use EnvUpdate() to refresh the environmental variables in the current logon session but the current running script will not see the changes. You can still do the action mentioned but you may need to use EnvSet() for the current running script thus it will see the environmental variables by a software method.

#RequireAdmin

; *** Not inherited for use in this script

; these entries add environmental variable entries to registry
RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "CATALINA_HOME" , "REG_SZ" , "C:\apache-tomcat-5.5.27")
RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "DERBY_INSTALL" , "REG_SZ" , "C:\db-derby-10.4.2.0-bin")
RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "JRE_HOME" , "REG_SZ" , "C:\Program Files\Java\jre1.5.0_05")
RegWrite("HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" , "JAVA_HOME" , "REG_SZ" , "C:\Program Files\Java\jdk1.5.0_05")

; this updates the environmental variable entries for subsequent executions other then current script execution
EnvUpdate()

; *** Inherited for use in this script

; these are for current script execution
EnvSet("CATALINA_HOME", "C:\apache-tomcat-5.5.27")
EnvSet("DERBY_INSTALL", "C:\db-derby-10.4.2.0-bin")
EnvSet("JRE_HOME", "C:\Program Files\Java\jre1.5.0_05")
EnvSet("JAVA_HOME", "C:\Program Files\Java\jdk1.5.0_05")

; test "CATALINA_HOME" environmental variable in current script
MsgBox(0, "CATALINA_HOME", EnvGet("CATALINA_HOME"))
Run("cmd /k echo %CATALINA_HOME%")

Share this post


Link to post
Share on other sites
beato

Thank you - this helped me out. Frustrating as I was just trying to set the Windows "temp" environment variable to C:\Temp for both Temp and Tmp.

I used "EnvUpdate" which set this but my program was performing a pre'check before launching the main application (check to make sure as our applications need C:\Temp). It failed when say a reboot, or logoff occurred e.g. Temp was set but was not active in the "session"

So after EnvUpdate was called I then followed it up with EnvSet and it appears that is what "applied" the Temp setting realtime. I'm not sure if I'm using it correctly but again seems to be working in my application:

If $Tempread <> "C:\Temp" Then
RegWrite("HKEY_CURRENT_USER\Environment", "Temp", "REG_SZ", "C:\Temp")
RegWrite("HKEY_CURRENT_USER\Environment", "Tmp", "REG_SZ", "C:\Temp")
EnvUpdate()
Sleep(1000)
EnvSet("Temp", "C:\Temp")
EnvSet("Tmp", "C:\Temp")
EndIf

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  

×