NSIS Overwrites Shortcuts - nsis

Is there any way to tell NSIS not to overwrite my start menu shortcut. The reason I don't want it to overwrite is so the user's command line options aren't cleared when they upgrade to a new version. I've tried this to no avail:
Section -AdditionalIcons
SetOverwrite off
CreateDirectory "${START_MENU_DIR}"
CreateShortCut "${START_MENU_LNK}" "$INSTDIR\${PRODUCT_NAME}.exe"
SectionEnd

Why can't you just check with IfFileExists ?
If you wanted to go all out, you could update the path and working dir, but leave the parameters and icon in place, but to do that you would have to call the IShellLink COM interface on your own (With the system plugin or a custom plugin/app)

Here is an example that works:
Section -AdditionalIcons
CreateDirectory "${START_MENU_DIR}"
IfFileExists "${START_MENU_LNK}" SkipShortcut
CreateShortCut "${START_MENU_LNK}" "$INSTDIR\${PRODUCT_NAME}.exe"
SkipShortcut:
SectionEnd

Related

How can I create a single NSIS script which will generate different installers based on an input parameter?

I have an application which has development, testing and live versions. I have a command procedure which currently creates 3 different versions of the installer, which can be installed on 3 separate computers.
What I would like to do would be to have one NSIS script which I pass in a parameter to, which will create one of the versions of the installer changing the name of the product and the installation folder. This will allow me to install all 3 versions on the same computer.
What I have tried so far is;
Function .onInit
Var /GLOBAL INSTALL_TYPE
${GetOptions} $CMDLINE "/t" $INSTALL_TYPE
${if} $INSTALL_TYPE == ""
StrCpy $INSTALL_TYPE "Live"
ReadEnvStr $R0 SYSTEMDRIVE
StrCpy $INSTDIR "$LOCALAPPDATA\Programs\MyComp\MyApp$INSTALL_TYPE\"
FunctionEnd
!define MUI_PRODUCT "FCDS-RECAP$INSTALL_TYPE"
OutFile "MyApp-$INSTALL_TYPEinstaller.exe"
One of the main errors I get has to do with MUI_PRODUCT and look similar to;
warning 6000: unknown variable/constant "INSTALL_TYPE.lnk" detected, ignoring (FullDeploymentUser.nsi:121)
warning 6000: unknown variable/constant "INSTALL_TYPE" detected, ignoring (FullDeploymentUser.nsi:124)
Two types of comments would be useful;
This is what you are doing wrong...
This is what you should be doing...
As always any help is appreciated.
MUI_PRODUCT is technically not an official NSIS define, some guy just invented it and used it in a guide.
All instructions starting with ! are preprocessor instructions, those and OutFile and File cannot be controlled by ${GetOptions} because they happen at compile time on your developer machine.
I don't really recommend this 3 in 1 installer solution, it is a bit complicated. It is much better to just create 3 different installers:
!ifndef APPTYPE
!error "APPTYPE not defined"
!endif
Name "MyApp ${APPTYPE}"
OutFile "MyApp ${APPTYPE} setup.exe"
InstallDir "$ProgramFiles\MyApp ${APPTYPE}"
Page Directory
Page InstFiles
Section
SetOutPath $InstDir
File /r "c:\myfiles\MyApp\${APPTYPE}\*"
SectionEnd
and then just generate them with makensis -DAPPTYPE=Beta myapp.nsi etc.
If you really want this 3 in 1 style then you need to use the macros in Sections.nsh to manipulate the sections so that only one of them is visible and active. You also need to mark the install somehow (.ini file?) so that your uninstaller also knows which install type it is uninstalling.

Run application after install(silent installer)

I want to run my application immediately after install and I understand the code to do it is as follows:
!define MUI_FINISHPAGE_RUN
!define MUI_FINISHPAGE_RUN_FUNCTION "LaunchLink"
!insertmacro MUI_PAGE_FINISH
Section
CreateShortcut "$DESKTOP\HelloWorldShortcut.lnk" "$INSTDIR\Hello World.exe" "dev03 3"
SectionEnd
Function LaunchLink
ExecShell "" "$DESKTOP\HelloWorldShortcut.lnk"
FunctionEnd
The problem is my installer is a silent installer but the above code adds a page to it.
Is there a way to use a silent installer to also run the application immediately after install?
A silent installer can just run the app as the final step in the last section. Whether or not it is a good idea for a silent installer to start the application is something you should think about, personally I would say no...
Section
SetOutPath $InstDir
File "MyApp.exe"
...
IfSilent "" +2 ; If the installer is always silent then you don't need this check
ExecShell "" "$InstDir\MyApp.exe"
SectionEnd

nsis uninstaller doesn't remove links

I have this issue:
in the installer sections I have this;
Section "Start Menu Shortcuts"
SetShellVarContext current
CreateDirectory "$SMPROGRAMS\myProgram"
CreateShortCut "$SMPROGRAMS\myProgram\myProgram.lnk" "$INSTDIR\myProgram.exe"
CreateShortCut "$SMPROGRAMS\myProgram\Uninstall myProgram.lnk" "$INSTDIR\myProgram-Uninstall.exe"
SectionEnd
Section "Desktop Shortcut"
SetShellVarContext current
CreateShortCut "$DESKTOP\myProgram.lnk" "$INSTDIR\myProgram.exe"
SectionEnd
and it works fine, I have the icon on the desktop and the icon plus the uninstall icon on the start\programs... tree
the uninstaller section is like this:
SetShellVarContext current
Delete "$DESKTOP\myProgram.lnk"
Delete "$SMPROGRAMS\myProgram\myProgram.lnk"
Delete "$SMPROGRAMS\myProgram\Uninstall myProgram.lnk"
RMDir "$SMPROGRAMS\myProgram"
and the desktop link was deleted, but the other folder with the links not..
any ideas?
the folder where is stored is this (i'm on win 7 64 bits):
C:\Users\Administrator\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
Do you have RequestExecutionLevel in your script? Without it Windows might do some compatibility hacks with your shortcuts.
If that does not help, try Process Monitor, it might be able to shed some light on the issue...

NSIS uninstaller - App Name missing (set dynamically)

I created an NSIS installer where the name of the app is taken from an .INI file (it has to be so since it will be used for multiple apps).
Name $APP_NAME
....
Function .onInit
ReadINIStr $R3 ${TECHPUB_INI_FILE} "General" "Installer_name"
StrCpy $APP_NAME $R3
....
FunctionEnd
....
Section install
....
WriteUninstaller $INSTDIR\Uninstall.exe
....
SectionEnd
The app name is correctly shown on the installer and it's the one from the .INI file. When I uninstall the app, the name is missing.
http://i48.tinypic.com/1934w9.png
Everything else works (uninstall removes all it has to remove). Any idea how to fix this?
Thank you!
The init function of the uninstaller is a separate un.onInit function. See Uninstall Callbacks.

cannot open fat jar from a desktop shortcut

the fat jar opens fine in the location i specified but it wont open when i call it through a desktop shortcut. Although if I right click on the icon and say open file location, it opens the correct file.
SetOutPath $INSTDIR
SetOverwrite on
File C:\jitconsole\JITConsole\jitconsole.jar
SetOutPath $INSTDIR\images
File C:\jitconsole\JITConsole\images\*
SetOutPath $INSTDIR\lib
File C:\jitconsole\JITConsole\lib\*
SetOutPath $DESKTOP
CreateShortcut $DESKTOP\JIT.lnk $INSTDIR\jitconsole.jar "" $INSTDIR\images\JIT_medium.ico
any help would be greatly appreciated
thanks
A .jar could open in any application, on my system it is set to open in WinRar!
You should create a shortcut that executes the correct command line:
CreateDirectory $Desktop ; Make sure desktop exists
SetOutPath $Instdir ; Sets the .lnk working directory
CreateShortcut "$DESKTOP\JIT.lnk" "c:\path\to\java.exe" "$INSTDIR\jitconsole.jar" "$INSTDIR\images\JIT_medium.ico"
This means you need to figure out the java path in the installer and if the java path changes your shortcut might break. It is probably a better idea to use a java loader app:
CreateDirectory $Desktop ; Make sure desktop exists
CreateShortcut "$DESKTOP\JIT.lnk" "$INSTDIR\MyJavaLoaderForMyApp.exe" "" "$INSTDIR\images\JIT_medium.ico"

Resources