pgg1
14th January 2008 11:21 UTC
Refreshing Environment Variable Table.
Hi
I have an application that is dependent on some dll's. These dll's are included in the installer. Once all the files and dll's have been installed I manipulate the search path and some system wide environment variables using Kickik's script which can be found here: http://nsis.sourceforge.net/Path_Manipulation
Once the installer has finished I can launch my application through any of the shortcuts I've created, everything works as expected.
What I would like to do is to launch the application from the finish page of the installer. The problem I have is that I get a UnsatisfiedLinkError (Java). This is because my application is not picking up the new PATH that I have just set. The new path contains the directory to my dll's.
What I need to do is to refresh the environment table after I have set the path so when my application launches from the finish page it will be able to pickup the dll's on the search path.
I have followed the following thread:
http://forums.winamp.com/showthread.php?threadid=273924
which adds some code to Kickik's script which refreshes the environment table. However, this does not work for me.
I have included Kickik's script with the modifications.
Could somebody please help me I've spent a lot of time on this and don't seem to be getting anywhere.
Regards
Paul
bholliger
14th January 2008 18:25 UTC
Hi there!
Well, this might not be what you expected, but it's a solution, that works:
Use FileWrite to write a batch file to the temp directory. Write something like
@echo off
set whatevervar=what you wanna set
set path=%path%;$INSTDIR
start myapplication.exe
And then just execute the batch file with ExecWait "mybatch.cmd". After execution you can delete the file. Your application gets the variables for the first time start. For upcoming starts, explorer has the right environment variables.
Cheers
Bruno
pgg1
15th January 2008 09:01 UTC
Thanks guys,
I'll take a look at both options.
Regards
Paul
pgg1
16th January 2008 19:28 UTC
Hi
I have looked at the batch option first and have used
nsExec::Exec '$0 /c "$TEMP\launchZang.cmd"'
instead of:
ExecWait "$TEMP\launchZang.cmd"
because I do not want the command shell to appear.
The following function is called from the finish page.
Function LaunchZang
ClearErrors
FileOpen $0 $TEMP\launchZang.cmd w
IfErrors done
FileWrite $0 "set ZBZ_HOME=$INSTDIR"
FileWrite $0 "$\r$\n"
FileWrite $0 "set FFMPEG_HOME=$INSTDIR\ffmpeg"
FileWrite $0 "$\r$\n"
FileWrite $0 "set path=%path%;${DLLS_ABSOLUTE_PATH}"
FileWrite $0 "$\r$\n"
FileWrite $0 'cd "$INSTDIR\client"'
FileWrite $0 "$\r$\n"
FileWrite $0 '"..\jre_v6\bin\javaw.exe" -cp .\BrowserLauncher2-10rc4.jar;.\Connected.jar;.\flickrapi-1.0b4.jar;.\jdic.jar;.\jh.jar;.\jregex1.2_01.jar;.\JSON.jar;.\mail.jar com.kc.pm.PhoneManager -Xmx210m'
FileClose $0
;ExecWait "$TEMP\launchZang.cmd"
SetOutPath "$TEMP"
ReadEnvStr $0 COMSPEC
nsExec::Exec '$0 /c "$TEMP\launchZang.cmd"'
done:
FunctionEnd
The application starts from the finish page which is what I wanted, the command prompt disappears which I want I want. All good, except the finish page of the installer hangs around. The installer is failing to exit/finish.
Any ideas?
Regards
Paul
bholliger
16th January 2008 19:46 UTC
I'd try kichik's idea or the following.
Execute the script in asynchronous mode:
SetOutPath "$TEMP"
ReadEnvStr $0 COMSPEC
ExecShell "open" $0 '/c "$TEMP\launchZang.cmd"' SW_HIDE
Sleep 2500
Delete /REBOOTOK "$TEMP\launchZang.cmd"
Cheers
Bruno
pgg1
17th January 2008 10:13 UTC
Thanks for the reply.
I've taken your code and everything works perfectly. I'm also going to look at kichik's idea.
Once again thank you.
Regards
Paul
pgg1
17th January 2008 13:35 UTC
Hi
I have also got it working using kichik's link.
Function LaunchZang
SetEnv::SetEnvVar "ZBZ_HOME" "$INSTDIR"
SetEnv::SetEnvVar "FFMPEG_HOME" "$INSTDIR\ffmpeg"
ReadEnvStr $R0 "PATH"
StrCpy $R0 "$R0;${DLLS_ABSOLUTE_PATH}"
SetEnv::SetEnvVar "PATH" $R0
ExecShell "open" "$SMPROGRAMS\${ZANG}\${ZANG}.lnk"
FunctionEnd
Thanks to the both of you.
Regards
Paul