How do you make an NSIS installer ad the installation directory to the Windows PATH environment variable?
Announcement
Collapse
No announcement yet.
Path
Collapse
X
-
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
-
-
You should start here:
Maybe try like this:
(Note that the new PATH may become effective only after a reboot)code:
ReadRegStr $0 HKCU "Environment" "Path" #read current PATH into $0
StrCpy $0 "C:\SomePath;$0" #prepend your path to the current PATH value
WriteRegStr HKCU "Environment" "Path" '$0' #write back the new PATHMy Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
Comment
-
-
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
Comment
-
-
Originally Posted by sethradio View PostI 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.
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:
@echo off
echo Setting up environment for Super Duper Tool...
set "PATH=C:\Path To Your Tool;%PATH%"My Plugins: StdUtils | NSISList | CPUFeatures | ExecTimeout | KillProc
My source of inspiration: http://youtu.be/lCwY4_0W1YI
Comment
-
-
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
Comment
-
-
Originally Posted by sethradio View PostI 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?
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
Comment
-
Comment