rename file with the name of installer name in NSIS installer? - windows

I'm working with NSIS installer. I need to change file defined in install path to the same installer name.
I try to use rename function like:
Rename "$INSTDIR\app.exe" "$INSTDIR\installname.exe"
but I need the installer name automatic.

Take a look at the constants, $EXEFILE is the filename, or $EXEPATH for the full path. If you want the name attribute you used in your source file, it is $(^Name)...

From FileFunc header you can combine GetExeName and GetFileName macros to get the installer's name:
!include "FileFunc.nsh"
OutFile test.exe
section main
${GetExeName} $R0
${GetFileName} "$R0" $R1
MessageBox MB_OK "My installer's exe is $R1"
sectionend
Now you can test it yourself.

Related

How to bundle exe file inside another exe file using nsis script

I have a installer file called sample.exe. This exe file will have some components that use have to be defined such as port number, installation directory and etc. I have to bundle this sample.exe file inside another installer called test.exe. So when i try to install the test.exe, it should also install the sample.exe. i could see there are options to achieve this in nsis, but how to provide options for the use to enter the port, directory path of sample.exe while installing the test.exe ? i am beginner to nsis and any reference are example script will help me lot. Thanks in advance.
You need to create custom (installer) page where these values are entered.
Use nsDialogs for this (recommended): http://nsis.sourceforge.net/Docs/nsDialogs/Readme.html
There is no exact solution for this as your specification is really vague, rather check the examples and use provided code snippets from them.
You generally use the directory page to let the user choose the installation directory. Non-standard user input can be recorded on a custom page using the nsDialogs plug-in:
Name "Foo"
OutFile "TestSetup.exe"
RequestExecutionLevel admin
InstallDir "$ProgramFiles\Test"
!define DEFAULTPORT 666
!include nsDialogs.nsh
Var MyPort
Var PortEdit
Function .onInit
StrCpy $MyPort "${DEFAULTPORT}"
FunctionEnd
Page Directory
Page Custom MyPageCreate MyPageLeave
Page InstFiles
Function MyPageCreate
nsDialogs::Create 1018
Pop $0
${NSD_CreateLabel} 0u 10% 20u 12u "Port: "
Pop $0
${NSD_CreateNumber} 20u 10% 40u 12u "$MyPort"
Pop $PortEdit
nsDialogs::Show
FunctionEnd
Function MyPageLeave
${NSD_GetText} $PortEdit $MyPort
FunctionEnd
Section
SetOutPath $InstDir
File "Sample.exe"
; Write the chosen port to a config file:
WriteIniStr "$InstDir\Config.ini" "Network" "Port" "$MyPort"
SectionEnd

How to set the ALL USER Directory as an output directory for a installer created with NSIS

I am trying to install a file to ALL USER DOCUMENTS Directory(windows 7) using NSIS.
In my code i am setting "SetShellVarContext all" but still the files are getting installed at current user directory
Please help
Here is my code
# define installer name
OutFile "installer.exe"
# set desktop as install directory
InstallDir $DOCUMENTS
# default section start
Section
# define output path
SetShellVarContext all
SetOutPath $INSTDIR
# specify file to go in output path
File test.txt
# define uninstaller name
WriteUninstaller $INSTDIR\uninstaller.exe
#-------
# default section end
SectionEnd
# create a section to define what the uninstaller does.
# the section will always be named "Uninstall"
Section "Uninstall"
# Always delete uninstaller first
Delete $INSTDIR\uninstaller.exe
# now delete installed file
Delete $INSTDIR\test.txt
SectionEnd
SetShellVarContext does not affect the InstallDir attribute, you must manually set $InstDir:
Function .onInit
SetShellVarContext all
StrCpy $InstDir $Documents
FunctionEnd

Adding extra command to cpack - NSIS packager/installer

I want to package a project of mine for windows with CPack and NSIS using an already existing
GeneratorConfig.cmake file where I want to add an extra command that will copy an .ini file called myProject.ini into %APPDATA%/myProject/myProject.ini .
This is GeneratorConfig.cmake
SET(INSTALL_AN_ALREADY_EXISTING_DIR ".")
##########################################################################
## Begin NSIS Specific options
##------------------------------------------------------------------------
if(CPACK_GENERATOR MATCHES NSIS)
# Additional NSIS commands to uninstall start menu shortcuts
SET(CPACK_NSIS_DELETE_ICONS_EXTRA
"Delete \"$SMPROGRAMS\\$MUI_TEMP\\${PROJECT_NAME}.lnk\"
StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2
Delete \"$DESKTOP\\${PROJECT_NAME}.lnk\" ")
# The display name string that appears in the Windows Add/Remove Program control panel
SET(CPACK_NSIS_DISPLAY_NAME "${PROJECT_NAME} ${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")
SET(CPACK_NSIS_DISPLAY_NAME_SET "TRUE")
# Extra NSIS commands that will be added to the end of the install Section, after your
# install tree is available on the target system.
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
"CreateShortCut \"$SMPROGRAMS\\$STARTMENU_FOLDER\\${PROJECT_NAME}.lnk\" \"$INSTDIR\\.\\bin\\${PROJECT_EXE} \" -previousworkingdir \"$INSTDIR\\.\\bin\\app_icon.ico\"
StrCmp \"$INSTALL_DESKTOP\" \"1\" 0 +2
CreateShortCut \"$DESKTOP\\${PROJECT_NAME}.lnk\" \"$INSTDIR\\.\\bin\\${PROJECT_EXE} \" -previousworkingdir \"$INSTDIR\\.\\bin\\app_icon.ico\"
")
# Extra commands to fix permissions of bin/licenses folder
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
"${CPACK_NSIS_EXTRA_INSTALL_COMMANDS}
ExecWait 'icacls \\\"$INSTDIR\\\\bin\\\\licenses\\\" /grant:r Users:\\\(OI\\\)\\\(CI\\\)\\\(F\\\)'
")
# A path to the executable that contains the installer icon.
SET(CPACK_NSIS_INSTALLED_ICON_NAME "${PROJECT__DIR}\\bin\\${PROJECT_EXE}")
# The default installation directory presented to the end user by the NSIS installer
SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
# Title displayed at the top of the installer
SET(CPACK_NSIS_PACKAGE_NAME "${PROJECT_NAME} ${PROJECT_VER_MAJOR}.${PROJECT_VER_MINOR}")
SET(CPACK_NSIS_PAGE_COMPONENTS " ")
SET(CPACK_NSIS_MUI_FINISHPAGE_RUN ${PROJECT_EXE})
endif(CPACK_GENERATOR MATCHES NSIS)
##------------------------------------------------------------------------
## End NSIS Specific options
##########################################################################
I tried to do this with the code below but this builds the package but doesn't
copy myProject.ini anywhere.
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
"CreateDirectory \"$ENV{APPDATA}\\myProject\",
SetOutPath \"$ENV{APPDATA}\\myProject\",
File \"myProject.ini\"
")
Any help or suggestions will be appreciated.
From what i can tell you are using not enough '\' symbols.
To clarify: that string is evaluated twice, once by CMake and once by CPack, and each time substitutions such as \->\ and \" -> " occur. Please check generated nsis project for what the actual generated commands are and whether all '"' are correctly set.
To summarize: try using this:
SET(CPACK_NSIS_EXTRA_INSTALL_COMMANDS
"CreateDirectory \\\"$ENV{APPDATA}\\\\myProject\\\",
SetOutPath \\\"$ENV{APPDATA}\\\\myProject\\\",
File \\\"myProject.ini\\\"
")

How to access InstallDirRegKey in NSIS

I can specify installation directory and registry value in NSIS like this:
InstallDir "$PROGRAMFILES\CTVI"
InstallDirRegKey HKLM "Software\CTVI" "Install_Dir"
Now I can access InstallDir by using the notation $INSTDIR throughout the script. How do I similarly access InstallDirRegKey? Is there a similar notation as there exists for InstallDir? I tried $INSTDIRREGKEY but that is not. Now what I do is that I type HKLM "Software\CTVI" "Install_Dir" everytime I require it. But that is not so DRY :)
When the InstallDirRegKey attribute is used, NSIS will look-up the specified registry entry at startup and if it finds a path there it will place that value in $Instdir before any of your code runs...

Create more than 1 uninstaller in a NSIS Section

Can a NSIS Section create more than 1 uninstaller?
My installer can install plugins for 3 different versions of an Application - therefore theres 3 different directories where the installer will install the files.
In each of those directories I want to add an uninstaller file that will remove only the files in that directory.
Each of the 3 uninstall files are created within the same Section area, is this invalid? How can I get my script to create 3 uninstallers(if possible)?
The following Section only creates one uninstaller, the last one(Version 10 uninstaller):
Section "Install Plugin Files" MainSetup
CheckInstallVers8:
IntCmp $installVers8 1 InstallVersion8 CheckInstallVers9 InstallVersion8
CheckInstallVers9:
IntCmp $installVers9 1 InstallVersion9 CheckInstallVers10 InstallVersion9
CheckInstallVers10:
IntCmp $installVers10 1 InstallVersion10 MainInstallation InstallVersion10
InstallVersion8:
# install plugins...
SetOutPath $VERS8DIR
writeUninstaller "${APPNAME} Uninstall.exe"
GoTo CheckInstallVers9
InstallVersion9:
SetOutPath $VERS9DIR
writeUninstaller "${APPNAME} Uninstall.exe"
GoTo CheckInstallVers10
InstallVersion10:
SetOutPath $VERS10DIR
writeUninstaller "${APPNAME} Uninstall.exe"
SectionEnd
You can call WriteUninstaller as many times as you want but you should use the full path name (writeUninstaller "$VERSxDIR\${APPNAME} Uninstall.exe")
You did not post a full script so it is hard to tell what is wrong with the logic (You might want to use LogicLib.nsh so you can do {IF}s) but you should be able to "MessageBox debug" your way to the solution.
One thing you did not talk about that might be relevant is the uninstaller logic. If the 3 uninstallers all do the exact same task then this is not an issue but I'd expect at least a difference in the uninstaller registry registration.
There are two ways to deal with this:
Tag data to the end of the uninstaller (or a .ini in the same directory)
Use !system to call makensis.exe and generate uninstallers at compile time that you include as normal Files
A different solution that might be relevant for plugins in sub-directories is to use a component page in the uninstaller and only delete the uninstaller when all 3 plugins have been removed...

Resources