fightstarr20
fightstarr20

Reputation: 12598

NSIS Installer Start Menu Directory

I have an NSIS installer that has the start menu folders hard-coded using this code...

Var SMDir ;Start menu folder
!insertmacro MUI_PAGE_STARTMENU 0 $SMDir

Section -StartMenu
  !insertmacro MUI_STARTMENU_WRITE_BEGIN 0
  CreateDirectory "$SMPrograms\MY Program\My Folder"
  CreateShortCut "$DESKTOP\My Program" "$INSTDIR\start.exe"
  CreateShortCut "$SMPROGRAMS\MY Program\My Shortcut.lnk" "$INSTDIR\start.exe"
  CreateShortCut "$SMPROGRAMS\My Program\Uninstall.lnk" "$INSTDIR\uninstall.exe"

This all works apart from on the 'Choose Start Menu Folder' it doesn't let me change the default installation directory.

Is there a way to fix this or alternatively how can I skip this page but still trigger the StartMenu section?

Upvotes: 2

Views: 9247

Answers (1)

Anders
Anders

Reputation: 101636

If you don't want a startmenu selection page at all just remove !insertmacro MUI_PAGE_STARTMENU ... and the two !insertmacro MUI_STARTMENU_* macros in the -StartMenu section.

If you want to allow the user to choose the directory then you must use the variable and not hardcode the path:

outfile test.exe
name "SM Test"
requestexecutionlevel user ;Single user/"Just me" installer

!define MUI_COMPONENTSPAGE_NODESC
!include mui2.nsh

Var SMDir ;Start menu folder
!insertmacro MUI_PAGE_COMPONENTS
;!define MUI_STARTMENUPAGE_DEFAULTFOLDER "MY Program" ;Default, name is used if not defined
!insertmacro MUI_PAGE_STARTMENU 0 $SMDir
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English


Section -StartMenu
!insertmacro MUI_STARTMENU_WRITE_BEGIN 0 ;This macro sets $SMDir and skips to MUI_STARTMENU_WRITE_END if the "Don't create shortcuts" checkbox is checked... 
CreateDirectory "$SMPrograms\$SMDir"
CreateShortCut "$SMPROGRAMS\$SMDir\Myapp.lnk" "$INSTDIR\start.exe"
!insertmacro MUI_STARTMENU_WRITE_END
SectionEnd

Section "Desktop Shortcut"
CreateShortCut "$DESKTOP\Myapp.lnk" "$INSTDIR\start.exe"
SectionEnd

(If you are installing as administrator then you should call SetShellVarContext all before accessing $SMPrograms and you should probably not create a desktop shortcut)

Upvotes: 3

Related Questions