|
![]() |
#1 |
Junior Member
Join Date: Oct 2011
Posts: 20
|
Path
How do you make an NSIS installer ad the installation directory to the Windows PATH environment variable?
|
![]() |
![]() |
![]() |
#2 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
The default environment variables for the current user are stored at:
HKEY_CURRENT_USER\Environment For the system (all users) they are stored at: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment You can use NSIS' registry functions to read the current value of "PATH", add your directory to it and write the new value back. My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#3 |
Junior Member
Join Date: Oct 2011
Posts: 20
|
Uh....
Could you show me some example code please?
|
![]() |
![]() |
![]() |
#4 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
You should start here:
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.2 Maybe try like this: code: (Note that the new PATH may become effective only after a reboot) My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#5 |
Junior Member
Join Date: Oct 2011
Posts: 20
|
Thanks!! You really are a major dude!!
![]() |
![]() |
![]() |
![]() |
#6 |
Moderator
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,333
|
This is not a good idea:
A) Why fill the global path with your crap, there is a total limit, what if all apps did this? It is possible to add per application path info in the registry under "App Paths" B) Using normal NSIS strings to manipulate global variables is a very bad idea, if the user has a %path% longer than 1024 you will corrupt their setup! IntOp $PostCount $PostCount + 1 |
![]() |
![]() |
![]() |
#7 |
Junior Member
Join Date: Oct 2011
Posts: 20
|
I will only use this if I am writing a command line tool. This allows users of a program to not have to type the full path to the executable.
|
![]() |
![]() |
![]() |
#8 | |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
Quote:
As an alternative you can add a shortcut to the Startmenu that opens a console with your tool added to the PATH, instead of adding your tool to the PATH globally. Many applications, like Visual Studio or GIT, use this technique. The command for the Startmenu shortcut could be something like: %comspec% /k ""$INSTDIR\setpath.bat"" And the "setpath.bat" could be created on-the-fly by the installer and should look like: code: My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
|
![]() |
![]() |
![]() |
#9 |
Junior Member
Join Date: Oct 2011
Posts: 20
|
How would I remove them
How do I remove the install path from the environment variable in the uninstaller?
|
![]() |
![]() |
![]() |
#10 |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
Option 1:
Backup the "old" path at install time. Restore it at un-install time. Chnages that have been made since install will be lost! Option 2: Read the current PATH at un-install time and use string functions to find "your" path in the current PATH. If found, remove only that part and write the modified PATH back. Harder to do than Option 1, but no changes made by other apps will be lost. However this solution again has the problem that "standard" NSIS can not cope with strings longer than 1024 characters! Option 3: Avoid modifying the global PATH environment variable from the very beginning, as has been suggested before in this thread. No problem with un-install and no NSIS string limitations. Probably the cleanest solution that you can go for... My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
![]() |
![]() |
![]() |
#11 |
Junior Member
Join Date: Oct 2011
Posts: 20
|
I know I shouldn't use nsis string functions to edit the pah variable at this point. But for the sake of it, how could you use string function to find the install path?
|
![]() |
![]() |
![]() |
#12 | |
Major Dude
Join Date: Sep 2005
Location: Somewhere over the Slaughterhouse
Posts: 797
|
Quote:
At install time, simply save your $INSTDIR to some (unique) registry key of your own. At un-install time, read that registry key. No string manipulations will be required. And, as on Windows the MAX_PATH is 260, the 1024 characters of an NISIS string are sufficient - for a single path. (Actually the uninstaller will already have $INSTDIR set to the path it was started from) My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc My source of inspiration: http://youtu.be/lCwY4_0W1YI |
|
![]() |
![]() |
![]() |
|
Tags |
nsis, path |
Thread Tools | Search this Thread |
Display Modes | |
|
|