Run an application shortcut after an install

From NSIS Wiki
Jump to navigationJump to search
Author: jpannequin (talk, contrib)


Description

Here is how to launch a shortcut at the end of an install (in the MUI). You may need this if you need to use a specific working directory and don't want to modify the MUI.

Usage

So suppose I want to launch "C:\User\test.lnk".

Before calling the macro for finish, you must define the run variables. If you define

!define MUI_FINISHPAGE_RUN "C:\User\test.lnk"

it will not work, because it is not an application.

You must set MUI_FINISHPAGE_RUN empty, and use a function instead.

!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_TEXT "Start a shortcut"
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!insertmacro MUI_PAGE_FINISH

You can then define the function and execute the link with ExecShell.

Function LaunchLink
  ExecShell "" "C:\User\test.lnk"
FunctionEnd

L d allan 07:24, 2 February 2006 (PST) Here is a complete nsis mui script

# Based on NSIS MUI Basic Example Script written by Joost Verburg (thx!)
  !include "MUI.nsh"
  Name "Modern UI Test"
  OutFile "MuiFinishPageRunFunction.exe"
  InstallDir "$PROGRAMFILES\Modern UI Test"
  InstallDirRegKey HKCU "Software\Modern UI Test" ""
 
  ShowInstDetails show
;--------------------------------
;Pages
  !insertmacro MUI_PAGE_WELCOME
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
 
    # These indented statements modify settings for MUI_PAGE_FINISH
    !define MUI_FINISHPAGE_NOAUTOCLOSE
    !define MUI_FINISHPAGE_RUN
    !define MUI_FINISHPAGE_RUN_NOTCHECKED
    !define MUI_FINISHPAGE_RUN_TEXT "Start a shortcut"
    !define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
    !define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
    !define MUI_FINISHPAGE_SHOWREADME $INSTDIR\readme.txt
  !insertmacro MUI_PAGE_FINISH
 
;Languages
!insertmacro MUI_LANGUAGE "English"
 
;--------------------------------
# No components page, so this is anonymous
Section "Dummy Section" SecDummy
  SetOutPath "$INSTDIR"
  File readme.txt
  WriteRegStr HKCU "Software\Modern UI Test" "" $INSTDIR
  WriteUninstaller "$INSTDIR\Uninstall.exe"
  DetailPrint "Reached Dummy section"
SectionEnd
 
Section "Uninstall"
  Delete "$INSTDIR\Uninstall.exe"
  RMDir "$INSTDIR"
  DeleteRegKey /ifempty HKCU "Software\Modern UI Test"
SectionEnd
 
Function LaunchLink
  MessageBox MB_OK "Reached LaunchLink $\r$\n \
                   SMPROGRAMS: $SMPROGRAMS  $\r$\n \
                   Start Menu Folder: $STARTMENU_FOLDER $\r$\n \
                   InstallDirectory: $INSTDIR "
  ExecShell "" "C:\User\test.lnk"
FunctionEnd