NSIS MUI_FINISHPAGE_RUN - nsis

I don't understand why:
If I use
!define MUI_FINISHPAGE_RUN notepad.exe
it works, Notepad starts.
If I use
!define MUI_FINISHPAGE_RUN winword.exe
nothing happens.

Notepad is in the Windows directory and that directory is searched by Exec. Winword is in some subfolder under program files most likely (and not a part of %path%) and therefore it is not found.
The best solution is to provide the full path to the application you want to run.
Normally you do
!define MUI_FINISHPAGE_RUN "$InstDir\MyApp.exe"
You could try
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION myrun
!insertmacro MUI_PAGE_FINISH
Function myrun
ExecShell "" "winword.exe"
FunctionEnd
This will work if Word registers itself in the App Paths key. Alternatively you could ExecShell a .Doc file if you know Word is installed.

Related

!define MUI_PAGE_DIRECTORY_VARIABLE does not create variable - NSIS

I'm trying to create an NSIS script which copies various files to two different locations that can be specified.
I have checked the documentation and other StackOverflow entries but do not come up with a solution.
My Problem is that I want to define a second variable for a directory. In this directory sample files and projects shall be copied.
When trying to compile the NSI I get the following error/warnings:
3 warnings:
unknown variable/constant "APPDIR" detected, ignoring (C:\Users\max\Desktop\PortablePlayer\so.nsi:29)
unknown variable/constant "APPDIR" detected, ignoring (C:\Users\max\Desktop\PortablePlayer\so.nsi:33)
unknown variable/constant "APPDIR\Testfile.txt" detected, ignoring (C:\Users\max\Desktop\PortablePlayer\so.nsi:43)
Here is my script that I'm using:
!include "MUI.nsh"
Name "MyApp"
OutFile "MyApp-Installer.exe"
InstallDir "$PROGRAMFILES\My App"
; Installation Directory for the App
!insertmacro MUI_PAGE_DIRECTORY
; Installation Directory for the samples and projects
!define MUI_PAGE_HEADER_SUBTEXT "Choose your custom Samples Folder"
!define MUI_DIRECTORYPAGE_TEXT_TOP "To separate your App and your samples and projects you can choose a different folder than the installation directory"
!define MUI_PAGE_DIRECTORY_VARIABLE $APPDIR
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section ""
SetOutPath $INSTDIR
File Testfile.txt
SetOutPath $APPDIR
File Testfile.txt
FileOpen $0 "$DESKTOP\Hello_world.txt" w
FileWrite $0 $APPDIR
FileClose $0
WriteUninstaller "$INSTDIR\MyApp-Uninstaller.exe"
SectionEnd
Section "Uninstall"
Delete "$INSTDIR\Testfile.txt"
Delete "$INSTDIR\MyApp-Uninstaller.exe"
RMDir $INSTDIR
Delete "$APPDIR\Testfile.txt"
SectionEnd
For debugging I tried to write the value of $APPDIR into a textfile but it only writes $APPDIR instead of the value.
If I change it to $INSTDIR it prints the correct path for $INSTDIR.
How can I initialize the variable for $APPDIR?
If I try to initialize it on the top, it is there but empty, so the installer fails after succesful compilation of the script.
Running Win 7 with NSIS 2.5.1
Can anybody please shed some light on what is wrong?
Thanks!
The MUI_DIRECTORYPAGE_VARIABLE define tells MUI that you have a custom variable that you want to use but MUI does not create the variable, you have to do that yourself near the top of your script:
Var APPDIR
So it should look something like
Var APPDIR
!include "MUI.nsh"
!define MUI_DIRECTORYPAGE_VARIABLE $APPDIR
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section
DetailPrint $APPDIR
SectionEnd
Edit: The name of the define is MUI_DIRECTORYPAGE_VARIABLE not MUI_PAGE_DIRECTORY_VARIABLE like you have in your example...

With NSIS can I share values between MUI_PAGE_DIRECTORY pages?

I have two MUI_PAGE_DIRECTORY pages. The first stores the entered data to the default, $INSTDIR. What I would like to do is copy the value in $INSTDIR to the defined var $DataDir so that before the second directory page is displayed, $DataDir becomes $INSTDIR\Data. When the second page is displayed I would like the default value to be $INSTDIR\Data.
Is this possible?
InstallDir $ProgramFiles\MyApp
Var DataDir
!include MUI2.nsh
!define MUI_PAGE_CUSTOMFUNCTION_LEAVE InstDirPageLeave
!insertmacro MUI_PAGE_DIRECTORY
!define MUI_DIRECTORYPAGE_VARIABLE $DataDir
!define MUI_DIRECTORYPAGE_TEXT_TOP "Choose Data directory for bla bla bla..."
!define MUI_DIRECTORYPAGE_TEXT_DESTINATION "Data Directory:"
!define MUI_PAGE_CUSTOMFUNCTION_SHOW DataDirShowPage
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE English
Function InstDirPageLeave
StrCpy $DataDir "$InstDir\Data"
FunctionEnd
Function DataDirShowPage
!insertmacro MUI_HEADER_TEXT "Foo" "Bar"
FunctionEnd
Section
DetailPrint $InstDir
DetailPrint $DataDir
SectionEnd
What are you trying to achieve?
If you want to install some files into two separate locations use MUI_PAGE_DIRECTORY and custom nsDialogs page (with browse folder button) so user can pick up two directories.
If your location is always $INSTDIR and second is somewhere inside it ($INSTDIR\some\data\path) then you only need to append your inside path to $INSTDIR - there is no need to show dialog twice and select path twice.

Creating shortcut with NSIS

I am trying to create an installer using NSIS, installing just the program that I have made works just fine but when I add code to the script to install a shortcut as well things aren't working.
I am very new to this program and what happens is the "Start in:" property path is incomplete but if i add the "\IndieBrowser\IndieBrowser\bin\Debug\IndieBrowser.exe"" at the end it just turns a lot of things into folders.
Full code:
!include "MUI2.nsh"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Section "Desktop Shortcut" SectionS
SetShellVarContext current
SetOutPath "$INSTDIR"
CreateShortCut "$DESKTOP\IndieBrowser.lnk" "$INSTDIR\IndieBrowser\IndieBrowser\bin\Debug\IndieBrowser.exe"
SectionEnd
Here is an example:
; Create application shortcut (first in installation dir to have the correct "start in" target)
SetOutPath "$INSTDIR\bin"
CreateShortCut "$INSTDIR\bin\${NAME}.lnk" "$INSTDIR\bin\${NAME}.exe"
; Start menu entries
SetOutPath "$SMPROGRAMS\${NAME}\"
CopyFiles "$INSTDIR\bin\${NAME}.lnk" "$SMPROGRAMS\${NAME}\"
Delete "$INSTDIR\bin\${NAME}.lnk"

Executing Bat File in NSIS installer-not working

I have builded nsis script successfully for my java project.I have a batch file that I need to run within my NSIS installer.It must run after all the files have been extracted.I have tried following commands
!define MUI_FINISHPAGE_RUN $INSTDIR\bin\batch.bat
This one also have tried:
SetOutPath $INSTDIR
ExpandEnvStrings $0 %COMSPEC%
nsExec::ExecToStack '"$INSTDIR\batch.bat"'
I have referred this link.
My Requirement is:
1.How to start batch file after installation completion using Nsis script?
Why call ExpandEnvStrings if you are not going to use the result? The path does not even match in your two examples.
As long as you get the path and quotes correct it should work:
!include MUI2.nsh
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION RunBatch
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_LANGUAGE English
Function RunBatch
;The most basic version, runs with visible console:
ExecWait '"$temp\test.cmd" /foo "bar baz" /blergh'
;You must use cmd.exe if you want redirection (With stupid extra quotes for cmd.exe):
ExpandEnvStrings $0 %COMSPEC%
ExecWait '"$0" /C ""$temp\test.cmd" /foo "bar baz" /blergh > "$temp\stdout.txt""'
;Use one of the exec plugins if you want to hide the console:
nsExec::Exec '"$temp\test.cmd" /foo "bar baz" /blergh'
FunctionEnd
There are several exec plugins you can use depending on your needs: nsExec, ExecDos
or ExecCmd

NSIS script condition compilation based upon existence of a file

I have an NSIS based installer that I need to be able generate slightly different versions of under different conditions.
The conditions are easy to establish at compile time, if a particular file exists on the disk then the alternative branding can be used. I know I could use a command-line option to the makensis.exe to provide this behaviour, but it would be better if the compiler could take care of this for me.
Is there a way of making a compile time "IfExist" type logic?
!macro CompileTimeIfFileExist path define
!tempfile tmpinc
!system 'IF EXIST "${path}" echo !define ${define} > "${tmpinc}"'
!include "${tmpinc}"
!delfile "${tmpinc}"
!undef tmpinc
!macroend
Section
!insertmacro CompileTimeIfFileExist "$%windir%\explorer.exe" itsThere
!ifdef itsThere
MessageBox mb_Topmost yes
!else
MessageBox mb_Topmost no
!endif
SectionEnd
Note: the !system command used here assumes you are compiling on windows
I don't have the answer to your generic question of compile-time file detection, but I do have a solution to what it sounds like you're trying to accomplish.
My installers use something like this:
In the file CustomBranding.nsh:
!define CUSTOM_BRANDING
!define APPNAME "Brand X"
!define LOGO "C:\Brand_X_Logo.png"
In the main installer script:
!include /NONFATAL "CustomBranding.nsh"
!ifndef CUSTOM_BRANDING
!define APPNAME "Generic"
!define LOGO "C:\Generic_Logo.png"
!endif
Is that the kind of "alternative branding" you're asking about?

Resources