ur

how to reload environment variables

18 posts in this topic

#1 ·  Posted

I am installing an setup.exe file through autoit runwait.

And after installation , I need to test the application shortcut.

Initially I have completed installation part and the shortcut functionality part I have done separately.

Both are working as separate exe files(.au3 compiled versions).

But as a final product, when I combined both of them, I am getting the error during shortcut launch as JRE_HOME variable not set.

I think, when both are separate exe files, the env. variable is being set by setup file during first au3 file.

And for second au3 as it is completely separate executable, it is loading the env variables from system at that point of time.

But for combined version, even though it is being set in the system, the au3 being run is not taking the latest values set during its runtime.

I tried restarting the explorer process also by using 

Run("explorer.exe",Call(ProcessClose("explorer.exe")));restart explorer

But still no use.

Can anyone provide your suggestions, how to handle this.

Share this post


Link to post
Share on other sites



#2 ·  Posted

Did you try EnvUpdate() ?

Jos

Ps: Don't know how you dreamed up that Run() statement but it looks quite "creative"


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks @Jos for your inputs.

But the EnvUpdate is also not helpful.

 

I am still getting the below prompt during the application launch.

 

Capture.PNG

 

 

Share this post


Link to post
Share on other sites

#5 ·  Posted

20 minutes ago, ur said:

But the EnvUpdate is also not helpful.

I am still getting the below prompt during the application launch.

What about you share the script so we understand why you get this error? 

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted

16 minutes ago, aa2zz6 said:

I did a google search and maybe this will help you setup the java environment variables with an Autoit script.

http://trompelecode.com/blog/2009/04/autoit-script-to-set-java-home/

The env variable is setting up by the setup.exe itself which i am executing using runwait from my autoit script.

It is updating in the env variables also.

But as already the au3 process started earlier itseld, the current process is not loading the variables

Share this post


Link to post
Share on other sites

#8 ·  Posted

THe env variable is being set by a thridparty setup file which I am launching from RunWait.

Once the process is completed, I am launcing the shortcut it created and it needs JRE_HOME , which is set by exe.

ANd it is creating also, I can check that by launching cmd and typing %JRE_HOME%

But our au3 file is not loading that.

Even after EnvUpdate() also.It is showing the empty messagebox for below code.

MsgBox(0,"",EnvGet("JRE_HOME"))
EnvUpdate();reload env. variables
MsgBox(0,"",EnvGet("JRE_HOME"))

Any suggestions?

Share this post


Link to post
Share on other sites

#9 ·  Posted

Have you considered respawning your script and having it pick up where it left off?

Share this post


Link to post
Share on other sites

#10 ·  Posted

Initially both are two separate scripts.

1. For installation of 3rd party setup file.

2. For launching its shortcut and doing the functionality testing.

At that time it worked as the 2nd part is a separate process completely.

Now when I combined them, it is failing to load the variables created in the first part.

 

 

Share this post


Link to post
Share on other sites

#11 ·  Posted

As a temporary solution, I am reading the registry value for environment variables and setting it for the session.

Local $jre_env = RegRead("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment", "JRE_HOME")
    If Not @error Then
        Logging ("JRE_HOME from registries "& $jre_env)
    Else
        Logging ("Error : Unable to Retrieve JRE_HOME env variable from Registries")
        Exit
    EndIf
    EnvSet("JRE_HOME", $jre_env);set JRE_HOME = $jre_env
    
    Func Logging($sMessage,$sLogFile=@ScriptDir&"\Logging.log")
    If $sMessage = "" Then
        FileWriteLine($sLogFile, "")
    Else
        FileWrite($sLogFile,_NowCalc() & " :: " & $sMessage&@CRLF)
    EndIf
    EndFunc

Please let me know if you find any.

Share this post


Link to post
Share on other sites

#12 ·  Posted

6 hours ago, Danp2 said:

Have you considered respawning your script and having it pick up where it left off?

How to do that?

Share this post


Link to post
Share on other sites

#13 ·  Posted

Just now, ur said:

How to do that?

Launch another instance of your script using Run and pass a parameter to indicate that the script should skip to a specific point and continue. Exit the original instance.

Share this post


Link to post
Share on other sites

#14 ·  Posted

But it will be again a subprocess to the original one.And the variables won't get loaded right?

Share this post


Link to post
Share on other sites

#15 ·  Posted

Good question. Only way to know for sure would be to test it. ;-)

Share this post


Link to post
Share on other sites

#16 ·  Posted

I tried now...Same issue

Share this post


Link to post
Share on other sites

#17 ·  Posted

What about if you use RunAs instead?

Share this post


Link to post
Share on other sites

#18 ·  Posted

With a different user? But I need to launch program with the logged in user only. I will use the runas with same user credentials, may be it might work.i will let you know my inputs

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