Archive: PATH is erased/replaced


PATH is erased/replaced
Hi,
I've made a commandline utility (.exe) that depends on a couple of dll's.
After looking for some kind of packer that would allow me to let users download and use a single (working) exe (with the dll's included) it seems that is impossible.
So someone pointed me to NSIS, which is a great tool, although I don't actually need to install software.

Crucial in my setup is that users don't have to add the directory with the exe to their environmental PATH variable. NSIS does a great job with this but in my case it erased my entire PATH even though I used A(ppend).
Gladly enough I read a lot of related posts before I tried, so I made a backup of my PATH.
But I can't seem to find a solution to this problem. My PATH contains 1081 characters and slimming it down does solve the problem. But I can't ask my users to do that or otherwise I could just as well offer a zip and make them add the dir to their PATH themselves.

1)Is there a 'real' solution to this problem?
2)Can I otherwise somehow count the characters of their PATH variable and show a warning that their PATH will not be updated and that they will (still) have to add it themselves manually and show/link to a manual of how to do this?
3)The directory which should added to the PATH variable is now hardcoded in my nsi script, but when people choose to 'install' in another directory this won't be correct. How can I retrieve what 'custom' directory they choose and use that dir to append to their PATH?
4)As I said before: I'm not actually installing software, it's more like saving into a dir and setting up the PATH. So, can I leave out all the registry stuff from the example.nsi or can this be usefull for other things such as an uninstaller which in my case would be just to remove the dir+contents and the PATH var?

I'm using NSIS 2.45 and Windows XP.

Thanks in advance!

Although the provided examples seem quite easy to change to reflect my setup I'm still posting it to make sure it does not contain unwanted, unneeded or even dangerous stuff.

!include EnvVarUpdate.nsh
Name "MyApp"
OutFile
"MyApp_installer.exe"
InstallDir $PROGRAMFILES\MyApp
InstallDirRegKey HKLM
"Software\MyApp" "Install_Dir"
RequestExecutionLevel admin

Page components
Page directory
Page instfiles

UninstPage uninstConfirm
UninstPage instfiles

Section
"MyApp (required)"
SectionIn RO

SetOutPath $INSTDIR

File "MyApp.exe"
File "gc.dll"
File "neko.dll"
File "regexp.ndll"
File "std.ndll"
File "zlib.ndll"
File "LICENSE"
File "neko_source_download.txt"
File "howto.txt"

WriteRegStr HKLM SOFTWARE\MyApp
"Install_Dir" "$INSTDIR"

WriteRegStr HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "DisplayName" "MyApp"
WriteRegStr HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "NoModify" 1
WriteRegDWORD HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp" "NoRepair" 1
WriteUninstaller
"uninstall.exe"
${EnvVarUpdate} $0
"PATH" "A" "HKLM" "C:\Program Files\MyApp"
SectionEnd

Section
"Start Menu Shortcuts (uninstaller)"
CreateDirectory
"$SMPROGRAMS\MyApp"
CreateShortCut
"$SMPROGRAMS\MyApp\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut
"$SMPROGRAMS\MyApp\howto.lnk" "$INSTDIR\howto.txt" "" "$INSTDIR\howto.txt" 0
SectionEnd

Section
"Uninstall"
DeleteRegKey HKLM
"Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp"
DeleteRegKey HKLM SOFTWARE\MyApp

Delete $INSTDIR\MyApp.exe
Delete $INSTDIR\uninstall.exe
Delete $INSTDIR\gc.dll
Delete $INSTDIR\neko.dll
Delete $INSTDIR\regexp.ndll
Delete $INSTDIR\std.ndll
Delete $INSTDIR\zlib.ndll
Delete $INSTDIR\LICENSE
Delete $INSTDIR\neko_source_download.txt
Delete $INSTDIR\howto.txt

Delete
"$SMPROGRAMS\MyApp\*.*"

RMDir
"$SMPROGRAMS\MyApp"
RMDir
"$INSTDIR"

${un.EnvVarUpdate} $0
"PATH" "R" "HKLM" "C:\Program Files\MyApp"
SectionEnd

Cheers,

Jan

1)
yes, this is a known problem, someone(not me) needs to rewrite the path functions to use the system plugin and dynamic memory so you don't run into the 1024 limit. In the mean time you could use the large string build of nsis ( http://nsis.sourceforge.net/Special_Builds )

2) yes it would be possible to count (read the registry path string and check its length)

3) $instdir


Originally posted by Anders
1)In the mean time you could use the large string build of nsis ( http://nsis.sourceforge.net/Special_Builds )
Thanks, It does solve my problem. (I read about it but was under the false impression I had to build that from source.)
But yesterday I read in this thread that it could still go wrong. :eek:
http://forums.winamp.com/showthread....hreadid=302516 threadid=302516(last post)
I'd hate to erase someone's PATH (I surely would be furious if someone/thing did it to me)

Is there a reason the special build is not the default one? Are there any drawbacks or good reasons not to use it?
Originally posted by Anders
2) yes it would be possible to count (read the registry path string and check its length)
I guess I won't need to anymore since it works now.
Originally posted by Anders
3) $instdir
Ah, as simple as that, nice, works perfectly. Many thanks.

Cheers,
Jan