Old 22nd January 2011, 00:29   #1
bdbaddog
Junior Member
 
Join Date: Dec 2008
Posts: 7
in .OnInit StrCpy $INSTDIR "c:\MYDIR" has no effect?

Greetings,

Here's my complete .OnInit

code:
Function .onInit
# Change default base dir to C:\COMPANY
StrCpy $INSTDIR "C:\COMPANY"

InitPluginsDir
!insertmacro MULTIUSER_INIT

ReadRegStr $R0 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" \
"UninstallString"
StrCmp $R0 "" done

MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"$(^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

# let's get the install dir of previous version by copying all
# but the /uinstall.exe from the full path to the uninstaller.exe
#
StrCpy $R1 $R0 -13
ExecWait '$R0 _?=$R1' ;Do not copy the uninstaller to a temp file

IfErrors no_remove_uninstaller done
;You can either use Delete /REBOOTOK in the uninstaller or add some code
;here to remove the uninstaller. Use a registry key to check
;whether the user has chosen to uninstall. If you are using an uninstaller
;components page, make sure all sections are uninstalled.
no_remove_uninstaller:

done:

FunctionEnd



When I run the installer it still prompts me to install into:
c:\Program Files (x86)\myProduct

It seems like StrCpy $INSTDIR in the .OnInit is having no effect.

Any sugguestions on how to make this work?
bdbaddog is offline   Reply With Quote
Old 22nd January 2011, 06:12   #2
jiake
Senior Member
 
jiake's Avatar
 
Join Date: Oct 2007
Location: Shanghai, China
Posts: 207
For that you have specified InstallDir in your script, to replace the defualt one, using InstallDir $INSTDIR.

Contact me: 137729898@qq.com
jiake is offline   Reply With Quote
Old 23rd January 2011, 01:43   #3
bdbaddog
Junior Member
 
Join Date: Dec 2008
Posts: 7
InstallDir is $INSTDIR no change

Thanks for the suggestion.
It wasn't in my file.
I changed it, an still no change.

When it gets to the "Chose Install Location" page, it still defaulting to
c:\Program Files (x86)\Blah

I created a dummy installer with .onInit setting $INSTDIR and InstallDir $INSTDIR see below. It also doesn't obey my StrCpy $INSTDIR "C:\BLAH"..

Can someone else try the below, you'll need a README.txt in your work dir..

I'm hoping it's something really simple that I"m missing.

_Bill

code:
# Auto-generated by EclipseNSIS Script Wizard
# Jan 22, 2011 6:37:58 PM

Name "My Application"

# General Symbol Definitions
!define REGKEY "SOFTWARE\$(^Name)"

# MultiUser Symbol Definitions
!define MULTIUSER_EXECUTIONLEVEL Standard
!define MULTIUSER_INSTALLMODE_COMMANDLINE
!define MULTIUSER_INSTALLMODE_INSTDIR "My Application"
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_KEY "${REGKEY}"
!define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUE "Path"

# MUI Symbol Definitions
!define MUI_FINISHPAGE_NOAUTOCLOSE
!define MUI_STARTMENUPAGE_REGISTRY_ROOT HKLM
!define MUI_STARTMENUPAGE_NODISABLE
!define MUI_STARTMENUPAGE_REGISTRY_KEY ${REGKEY}
!define MUI_STARTMENUPAGE_REGISTRY_VALUENAME StartMenuGroup
!define MUI_STARTMENUPAGE_DEFAULTFOLDER "My Application"
!define MUI_UNFINISHPAGE_NOAUTOCLOSE

# Included files
!include MultiUser.nsh
!include Sections.nsh
!include MUI2.nsh

# Variables
Var StartMenuGroup

# Installer pages
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_STARTMENU Application $StartMenuGroup
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES

# Installer languages
!insertmacro MUI_LANGUAGE English

# Installer attributes
OutFile setup.exe
InstallDir $INSTDIR
CRCCheck on
XPStyle on
ShowInstDetails hide
InstallDirRegKey HKLM "${REGKEY}" Path
ShowUninstDetails hide

# Installer sections
Section -Main SEC0000
SetOutPath $INSTDIR
SetOverwrite on
File README.txt
WriteRegStr HKLM "${REGKEY}\Components" Main 1
SectionEnd

Section -post SEC0001
WriteRegStr HKLM "${REGKEY}" Path $INSTDIR
SetOutPath $INSTDIR
WriteUninstaller $INSTDIR\uninstall.exe
!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
SetOutPath $SMPROGRAMS\$StartMenuGroup
CreateShortcut "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk" $INSTDIR\uninstall.exe
!insertmacro MUI_STARTMENU_WRITE_END
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayName "$(^Name)"
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" DisplayIcon $INSTDIR\uninstall.exe
WriteRegStr HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" UninstallString $INSTDIR\uninstall.exe
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoModify 1
WriteRegDWORD HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)" NoRepair 1
SectionEnd

# Macro for selecting uninstaller sections
!macro SELECT_UNSECTION SECTION_NAME UNSECTION_ID
Push $R0
ReadRegStr $R0 HKLM "${REGKEY}\Components" "${SECTION_NAME}"
StrCmp $R0 1 0 next${UNSECTION_ID}
!insertmacro SelectSection "${UNSECTION_ID}"
GoTo done${UNSECTION_ID}
next${UNSECTION_ID}:
!insertmacro UnselectSection "${UNSECTION_ID}"
done${UNSECTION_ID}:
Pop $R0
!macroend

# Uninstaller sections
Section /o -un.Main UNSEC0000
Delete /REBOOTOK $INSTDIR\README.txt
DeleteRegValue HKLM "${REGKEY}\Components" Main
SectionEnd

Section -un.post UNSEC0001
DeleteRegKey HKLM "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$(^Name)"
Delete /REBOOTOK "$SMPROGRAMS\$StartMenuGroup\Uninstall $(^Name).lnk"
Delete /REBOOTOK $INSTDIR\uninstall.exe
DeleteRegValue HKLM "${REGKEY}" StartMenuGroup
DeleteRegValue HKLM "${REGKEY}" Path
DeleteRegKey /IfEmpty HKLM "${REGKEY}\Components"
DeleteRegKey /IfEmpty HKLM "${REGKEY}"
RmDir /REBOOTOK $SMPROGRAMS\$StartMenuGroup
RmDir /REBOOTOK $INSTDIR
SectionEnd

# Installer functions
Function .onInit
StrCpy $INSTDIR "C:\BLAHBLAH"
InitPluginsDir
!insertmacro MULTIUSER_INIT
FunctionEnd

# Uninstaller functions
Function un.onInit
!insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuGroup
!insertmacro MULTIUSER_UNINIT
!insertmacro SELECT_UNSECTION Main ${UNSEC0000}
FunctionEnd

bdbaddog is offline   Reply With Quote
Old 23rd January 2011, 08:01   #4
MSG
Major Dude
 
Join Date: Oct 2006
Posts: 1,892
I think "InstallDir $INSTDIR" is kind of pointless. the idea is to set the value of $instdir...
MSG is offline   Reply With Quote
Old 25th January 2011, 18:01   #5
bdbaddog
Junior Member
 
Join Date: Dec 2008
Posts: 7
is it $INSTDIR or $instdir

Either way.. The sample script doesn't alter the default install dir.

Doe anyone have a sample script which does?
bdbaddog is offline   Reply With Quote
Old 25th January 2011, 20:52   #6
Afrow UK
Moderator
 
Afrow UK's Avatar
 
Join Date: Nov 2002
Location: Surrey, England
Posts: 8,434
Try commenting out the two !define MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_* lines.

Stu
Afrow UK is offline   Reply With Quote
Old 25th January 2011, 22:06   #7
bdbaddog
Junior Member
 
Join Date: Dec 2008
Posts: 7
Got it..

This works

code:
Function .onInit
InitPluginsDir
!insertmacro MULTIUSER_INIT
StrCpy $INSTDIR "C:\BLAHBLAH"
FunctionEnd



This doesn't work

code:
Function .onInit
StrCpy $INSTDIR "C:\BLAHBLAH"
InitPluginsDir
!insertmacro MULTIUSER_INIT
FunctionEnd



It looks like "!insermacro MULTIUSER_INIT" must overwrite $INSTDIR
bdbaddog is offline   Reply With Quote
Old 25th January 2011, 23:26   #8
bdbaddog
Junior Member
 
Join Date: Dec 2008
Posts: 7
Also found you need to not define
MULTIUSER_INSTALLMODE_INSTDIR

Or it will prefix $INSTDIR as follows

!ifdef MULTIUSER_INSTALLMODE_INSTDIR
StrCpy $INSTDIR "$PROGRAMFILES\${MULTIUSER_INSTALLMODE_INSTDIR}"
!endif
bdbaddog is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

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