Old 28th August 2014, 10:58   #1
Lilou1515
Junior Member
 
Join Date: Aug 2014
Posts: 2
Problem with WriteRegStr (HKLM -> Run)

Hello.

I created a script to install my software on Windows. It should automatically start when a user logs on. The problem is that everytime I log on, a wrong version of my software automatically starts instead of the latest version.

I don't understand why it does not work correctly because I compiled my script whith the latest version of my program and I can see in the installation directory that the latest version is installed.

Thanks in advance for your help.

Here is my script :

; Script generated by the HM NIS Edit Script Wizard.

RequestExecutionLevel admin

; HM NIS Edit Wizard helper defines
!define PRODUCT_NAME "app"
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER "lol"
!define PRODUCT_WEB_SITE "http://www.lol.fr"
!define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\app.exe"
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM"


; MUI 1.67 compatible ------
!include "MUI2.nsh"
!include "FileFunc.nsh"
; MUI Settings
!define MUI_ABORTWARNING
!define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico"

; Language Selection Dialog Settings
!define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language"

; Welcome page
!insertmacro MUI_PAGE_WELCOME
; Directory page
!insertmacro MUI_PAGE_DIRECTORY
; Instfiles page
!insertmacro MUI_PAGE_INSTFILES
; Finish page
!define MUI_FINISHPAGE_RUN "$INSTDIR\app.exe"
!define MUI_FINISHPAGE_RUN_NOTCHECKED
!define MUI_FINISHPAGE_RUN_TEXT "Cochez pour démarrer app 1.0"
!define MUI_FINISHPAGE_TEXT "ATTENTION : Veuillez copier vos fichiers de licence dans le répertoire d'installation."
;!define MUI_FINISHPAGE_TEXT_REBOOT "Veuillez redémarrer votre ordinateur pour terminer l'installation."
!insertmacro MUI_PAGE_FINISH
; Uninstaller pages
!insertmacro MUI_UNPAGE_INSTFILES

; Language files
!insertmacro MUI_LANGUAGE "French"

; MUI end ------

Name "${PRODUCT_NAME} ${PRODUCT_VERSION}"
OutFile "Install.exe"
InstallDir "$PROGRAMFILES\app"
InstallDirRegKey HKLM "${PRODUCT_DIR_REGKEY}" ""
ShowInstDetails show
ShowUnInstDetails show

Function .onInit
!insertmacro MUI_LANGDLL_DISPLAY
;Install Visual C++ runtime elements to be able to launch app
Exec ".\vcredist_x86.exe"
;Remove comment to add auto restart at the end of the installation
;SetRebootFlag true
FunctionEnd

Section "SectionPrincipale" SEC01
SetOutPath "$INSTDIR"
SetOverwrite ifnewer
File ".\conf.ini"
File ".\app.exe"
CreateDirectory "$SMPROGRAMS\app"
CreateShortCut "$SMPROGRAMS\app\app.lnk" "$INSTDIR\app.exe"
CreateShortCut "$DESKTOP\app.lnk" "$INSTDIR\app.exe"

SectionEnd

Section -AdditionalIcons
WriteIniStr "$INSTDIR\${PRODUCT_NAME}.url" "InternetShortcut" "URL" "${PRODUCT_WEB_SITE}"
CreateShortCut "$SMPROGRAMS\app\Website.lnk" "$INSTDIR\${PRODUCT_NAME}.url"
CreateShortCut "$SMPROGRAMS\app\Uninstall.lnk" "$INSTDIR\uninst.exe"
SectionEnd

Section -Post
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "${PRODUCT_DIR_REGKEY}" "app" "$INSTDIR\app.exe"
;app will be launch each time the user logs on
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Run\" "app" "$INSTDIR\app.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayIcon" "$INSTDIR\app.exe"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "URLInfoAbout" "${PRODUCT_WEB_SITE}"
WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}"
SectionEnd

Function un.onUninstSuccess
HideWindow
MessageBox MB_ICONINFORMATION|MB_OK "app a été désinstallé avec succès de votre ordinateur."
FunctionEnd

Function un.onInit
!insertmacro MUI_UNGETLANGUAGE
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Êtes-vous certains de vouloir désinstaller totalement app et tous ses composants ?" IDYES +2
Abort
FunctionEnd

Section Uninstall
Delete "$INSTDIR\${PRODUCT_NAME}.url"
Delete "$INSTDIR\uninst.exe"
Delete "$INSTDIR\*.xml"
Delete "$SMPROGRAMS\app\Uninstall.lnk"
Delete "$SMPROGRAMS\app\Website.lnk"
Delete "$DESKTOP\app.lnk"
Delete "$SMPROGRAMS\app\app.lnk"
Delete "$INSTDIR\vcredist_x86.exe"

RMDir "$SMPROGRAMS\app"
RMDir "$INSTDIR"

DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}"
DeleteRegKey HKLM "${PRODUCT_DIR_REGKEY}"
SetAutoClose true
SectionEnd
Lilou1515 is offline   Reply With Quote
Old 28th August 2014, 15:21   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,296
Without actually looking at your script my guess is that you got a wrong path somewhere or also added a entry under HKCU at some point. Use a tool like AutoRuns (from sysinternals) to verify that the path is correct etc.

If this is a 64bit system then you also need to remember that there is a 32/64 registry split (SetRegView in NSIS)

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 29th August 2014, 18:29   #3
kolorowy
Junior Member
 
Join Date: Feb 2013
Posts: 9
Your run registry points to C:\Program Files (x86)\app\app.exe the reason is NSIS is 32bit application but that does not matter since windows can handle 32/64 run registry key.

If your old app is starting every time, and you have older files in the directory, it appears as SetOverwrite ifnewer does not work thus your files are not overwriten.

Personally I simply do not use SetOverwrite ifNewer, I simply overwrite files no matter what.
kolorowy is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Tags
hklm, logon, nsis, run, writeregstr

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump