Archive: addtopath function doesnt work anymore


addtopath function doesnt work anymore
i have used addtopath for some time, and it worked. now it seems it stopped working. did some new MS patch cause this not to work?

if i manually add it, the remove it from path in the uninstaller works fine. the adding doesnt!

Section "MainSection" SEC01
SetDetailsPrint textonly
DetailPrint "Installing My Special Software..."
SetDetailsPrint none
SetOutPath "$INSTDIR"
; WTF - not working - and it should - really - it should !!!
Push $INSTDIR
Call AddToPath
Push "PATH"
Push $INSTDIR
Call AddToEnvVar


Also, I noticed it sorta works on a select set of machines. However, when it adds it to the environment path, it doesnt refresh, like that moment pause if one were to do it manually to activate it. one of my files that needs to register resides in the product directory and when the dll registers, it wont work because the dependencies are there, but the system doesnt know about it!


Okay, another development. It still doesnt work on my desktop, but on my laptop, it adds the path, doesnt activate it still, and when i uninstall it gets removed. however, when i reinstall it, the path no longer gets added.


Are you saying Explorer doesn't refresh its environment table? If you Start->Run->cmd->echo %PATH% after installation, you don't see it there?


On my desktop, nothing ever shows up for %PATH%.
On my laptop, after I uninstall it, it shows up in the path variable. It does not show up in the path variable if you right click the system properties, but it still shows up when I echo it.

If I reboot the system, it finally removes itself from the path.

After installing the software again, it does not show up it the %PATH% and after rebooting the system it does show up.

I am using Windows XP SP2 on all systems. This has always worked in the past. Nothing has changed other than various MS patches and newer versions of the NSIS compiler. I do not know when this stopped working properly.


I works perfectly fine for me with a fully patched Windows XP SP2. AddToPath checks for the existence of the directory and if it's already in the PATH before actually adding it. Make sure that the directory exists and that you run your test installer from explorer.exe and not makensisw.exe or any other IDE so the environment will be up-to-date. Also try a small test version of the script that just adds a directory.


As you can see in my above code I call it after the directory gets created. i tried putting it towards the bottom with the same problem.

i run the setup.exe on two different laptops and both exhibit the same problem. one is a member of my corporate domain, and one is not.

both have the same issues. both require a reboot for %PATH% to be updated when installed, and when uninstalled. the uninstalled doesnt bother me as much, but the install does, since i need the instdir to be in the path to register certain dll files. i rather not copy them into system32 as when the product gets uninstalled i dont want them orphaned and i rather not touch a users system32.

so far, i cant see anything that is causing this. especially that nothing changed and it used to work in the past and now it doesnt.


And what about the stale environment block of your IDE? Are you running your installer from Explorer.exe? Are you running the program that you use to test the new PATH from Explorer.exe?


i am not running the installer from the IDE. I am running it from explorer because the file i saved on my flash drive and i saved it to the C drive on my test computers. I double click the setup.exe from there, in explorer.


And a script that just adds the directory to the path? Also try a script that does just the following after you manually add the directory to the registry (HKCU\Environment\PATH):

!include WinMessages.nsh
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

okay, i can now say wtf...bc my simple script worked. i even put some files that was causing the problem earlier.

and it worked.

interesting. even on my desktop that wasnt working from the beginning./ i dont know why it worked on others, 50%, but 0% on my desktop.

i guess now comes to figuring out why it doesnt work with my aster installer.

i do have a lot of tests going on, so perhaps that is the cause.


Attach your script, if you can, and I'll have a look as well.


well i tried to clean it up as possible, trying not to be too revealing...


!define PRODUCT_NAME "Phantom"
!define PRODUCT_VERSION "643"
!define PRODUCT_PUBLISHER "Company"
!define PRODUCT_WEB_SITE "mysite.com"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\PH643.EXE"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"
!define SHCNE_ASSOCCHANGED 0x08000000
!define SHCNF_IDLIST 0
!define ALL_USERS

!include "WinMessages.NSH"
!include "AddToPath.nsh"
!include WinVer.nsh

!include LogicLib.nsh

; lets try this compressor instead
SetCompressor lzma

; MUI 1.67 compatible ------
!include "MUI.nsh"

; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "setup.ico"


!define MUI_UNICON "uninstall.ico"

; Welcome page
!insertmacro MUI_PAGE_WELCOME

; eula
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE "END USER AGMT.rtf"
!define MUI_LICENSEPAGE_RADIOBUTTONS
!insertmacro MUI_PAGE_LICENSE "FIRMWARE_EULA.rtf"

; Instfiles page
!insertmacro MUI_PAGE_INSTFILES


; Finish page
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\README.rtf"
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!define MUI_FINISHPAGE_RUN "$INSTDIR\PH643.EXE"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!insertmacro MUI_PAGE_FINISH

; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "English"

; Reserve files
!insertmacro MUI_RESERVEFILE_INSTALLOPTIONS

BrandingText "${PRODUCT_PUBLISHER}"
; MUI end ------


Function .onInit


;; denied
GetVersion::WindowsName
Pop $R0

${If} $R0 == "XP"
Goto xp
${ElseIf} $R0 == "2000"
Goto go_away
${ElseIf} $R0 == "Server 2003"
Goto go_away
${Elseif} $R0 == "Server 2003 R2"
Goto go_away
${Else}
Goto error
${EndIf}

xp:
GetVersion::WindowsType
Pop $R0
StrCmp $R0 "Home Edition" xp_home_error go_away

xp_home_error:
MessageBox MB_OK|MB_ICONSTOP "Windows XP Home Edition is not supported by the software. $\n$\nPlease call 1-800-for additional support options." IDOK
Quit

error:
MessageBox MB_OK|MB_ICONSTOP "Windows $R0 is not supported by the software. $\n$\nPlease call 1-800- for additional support options." IDOK
Quit


go_away:

;;;;;;; DENY ALL OPERATING SYSTEMS BUT ALLOW SUPPORTED ONES:
;
; XP PRO
; 2000
; SERVER 2003
; SERVER 2003 R2
;
; AWAITING APPROVAL FOR:
;
; XP 64
; VISTA
; SERVER LONGHORN


ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}" \
"UninstallString"
StrCmp $R0 "" done

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"${PRODUCT_NAME} is already installed. $\n$\nClick `OK` to remove the \
previous version or `Cancel` to cancel this upgrade." \
IDOK uninst
Abort

;Run the uninstaller
uninst:
ClearErrors
ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file

IfErrors no_remove_uninstaller
no_remove_uninstaller:

done:

FunctionEnd

!define myStrStr "!insertmacro myStrStr"


Function RefreshShellIcons
; By jerome tremblay - april 2003
System::Call 'shell32.dll::SHChangeNotify(i, i, i, i) v \
(${SHCNE_ASSOCCHANGED}, ${SHCNF_IDLIST}, 0, 0)'
FunctionEnd


Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "setup.exe"
InstallDir "$PROGRAMFILES\Phantom"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails NeverShow
ShowUnInstDetails NeverShow

Section "MainSection" SEC01
SetDetailsPrint textonly
DetailPrint "Installing Phantom Software..."
SetDetailsPrint none
SetOutPath "$INSTDIR"
Push $INSTDIR
Call AddToPath
File "ijl15.dll"
File "ipl.dll"
File "ipla6.dll"
File "IPLM5.DLL"
File "PH643.EXE"
; ..... snip a roo
File "PHCON.DLL"
File "PHFILE.DLL"
File "PHINT.DLL"
File "PHSIG.DLL"
File "PHSIGV.DLL"
File "phicon.dll"
File "PhThumb.dll"
File "MFC71.dll"
File "Microsoft.VC80.CRT.manifest"
File "msvcm80.dll"
File "msvcp80.dll"
File "msvcr80.dll"
File "mfc80.dll"
File "Phantom.chm"
File "Release.chm"
File "TechSupp.chm"

; fix bug bc last version i over wrote the path
ReadRegStr $1 HKLM \
"SYSTEM\CurrentControlSet\Control\Session Manager\Environment" Path
Push $1
Push "wbem"
Call StrStr
Pop $R0

StrCmp $R0 "" true false

true:
; the item isnt here so add it now
Push "$sysdir\wbem"
Call AddToPath
Goto End

false:
;nothing to do today, hurray!
Goto End

End:

SetOutPath "$INSTDIR"
File "msvcr71.dll"

SetShellVarContext all
CreateShortCut "$DESKTOP\Panel.lnk" "$INSTDIR\PhPanel.exe"


${If} ${IsWinXP}
Goto section_xp
${EndIf}

${If} ${IsWin2000}
Goto section_2000
${EndIf}


section_xp:
SetDetailsPrint textonly
DetailPrint "Copying Windows XP IEEE 1394 Drivers..."
SetDetailsPrint none
SetOutPath "$INSTDIR\WinXP Drivers"
File "WinXP Drivers\Ph1394.dll"
File "WinXP Drivers\Ph1394.inf"
File "WinXP Drivers\Ph1394.sys"
SetOutPath "$INSTDIR\XP System Files"
File "XP System Files\1394bus.sys"
File "XP System Files\ohci1394.sys"
File "XP System Files\READ ME.txt"
Goto the_rest


section_2000:
SetDetailsPrint textonly
DetailPrint "Copying Windows 2000 IEEE 1394 Drivers..."
SetDetailsPrint none
SetOutPath "$INSTDIR\Win2K Camera Drivers"
File "Win2K Camera Drivers\Ph1394.dll"
File "Win2K Camera Drivers\Ph1394.inf"
File "Win2K Camera Drivers\Ph1394.sys"
SetOutPath "$INSTDIR\Win2k System Files"
File "Win2k System Files\1394bus.sys"
File "Win2k System Files\ohci1394.sys"
File "Win2k System Files\READ ME.txt"
Goto the_rest

the_rest:
UnRegDll "$INSTDIR\PhThumb.dll"
RegDll "$INSTDIR\PhThumb.dll"
SetOutPath "$INSTDIR"


SetDetailsPrint textonly
DetailPrint "Associating Movies to Software..."
SetDetailsPrint none
;; file associations for xxx file
; back up old value of .xxx
!define Index "Line${__LINE__}"
ReadRegStr $1 HKCR ".xxx" ""
StrCmp $1 "" "${Index}-NoBackup"
StrCmp $1 "XXXFile" "${Index}-NoBackup"
WriteRegStr HKCR ".xxx" "backup_val" $1
"${Index}-NoBackup:"
WriteRegStr HKCR ".xxx" "" "xxxFile"
ReadRegStr $0 HKCR "xxxFile" ""
StrCmp $0 "" 0 "${Index}-Skip"
WriteRegStr HKCR "xxxFile" "" "XXX File"
WriteRegStr HKCR "xxxFile\shell" "" "open"
WriteRegStr HKCR "xxxFile\DefaultIcon" "" "$INSTDIR\phicon.dll,1"
"${Index}-Skip:"
WriteRegStr HKCR "xxxFile\shell\open\command" "" \
'$INSTDIR\PH643.EXE "%1"'
!undef Index

;; file associations for cci file

; back up old value of .cci
!define Index "Line${__LINE__}"
ReadRegStr $1 HKCR ".cci" ""
StrCmp $1 "" "${Index}-NoBackup"
StrCmp $1 "PhantomCciFile" "${Index}-NoBackup"
WriteRegStr HKCR ".cci" "backup_val" $1
"${Index}-NoBackup:"
WriteRegStr HKCR ".cci" "" "PhantomCciFile"
ReadRegStr $0 HKCR "PhantomCciFile" ""
StrCmp $0 "" 0 "${Index}-Skip"
WriteRegStr HKCR "PhantomCciFile" "" "Phantom Cine File"
WriteRegStr HKCR "PhantomCciFile\shell" "" "open"
WriteRegStr HKCR "PhantomCciFile\DefaultIcon" "" "$INSTDIR\phicon.dll,0"
"${Index}-Skip:"
WriteRegStr HKCR "PhantomCciFile\shell\open\command" "" \
'$INSTDIR\PH643.EXE "%1"'
!undef Index


;;; add cine format as well??.... i say no, add cine format with 644+ with new phthumb!!!


; Rest of script
Call RefreshShellIcons
SectionEnd

Please attach large scripts next time.


Originally posted by kichik
Please attach large scripts next time.
sorry... :(

I looked and relooked at the code and I really can't find anything that would cause this to stop working. Can the OS denial stuff include some headers that can cause it to stop? I think thats about the only thing I changed recently.


Maybe a local version of WinMessages.nsh overriding the one from nsisdir\Include? Take a look at the makensis log and look for the SendMessage line. Make sure it has normal values and not zeros or unexpanded strings.


SendMessage: (timeout=5000)(0xFFFF,0x001A,0,STR:Environment)


No winmessages in any directory other than include