Setup programs for Windows

Alberto, why did you chose NSIS to build setup programs? I don’t like it because its scripting language seems a mix between assembly and shell scripting and it doesn’t even have flow control statements, you have to use Goto!

Moreover you have to do manually everthing, for instance to copy a file that later can be uninstalled you need this code:

; Copy the file
File "example.exe"

; Create shortcuts.
CeateDirectory "$SMPROGRAMS\Example"
CreateShortCut "$SMPROGRAMS\Example\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
CreateShortCut "$SMPROGRAMS\Example\Example.lnk" "$INSTDIR\example.exe" "" "$INSTDIR\example.exe" 0

; Copy the uninstaller.
WriteUninstaller "uninstall.exe"

; Write the uninstall keys for Windows.
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example" "DisplayName" "NSIS Example"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example" "UninstallString" '"$INSTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersionUninstall\Example" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example" "NoRepair" 1 WriteUninstaller "uninstall.exe"

And then you have to uninstall everything manually:

; Delete registry keys.
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Example"

; Remove files and uninstaller.
Delete $INSTDIR\example.exe
Delete $INSTDIR\uninstall.exe

; Remove shortcuts.
Delete "$SMPROGRAMS\Example\Uninstall.lnk"
Delete "$SMPROGRAMS\Example\Example.lnk"
RMDir "$SMPROGRAMS\Example"

; Remove the program directory.
RMDir "$INSTDIR"

I prefer Inno Setup, the nice thing is that for common tasks (copying files, creating shortcuts, adding registry keys, etc.) you only have to write a simple ini-like file, but if you need something more powerful you can use Pascal scripting.

The previous example in Inno Setup would be:

[Files]
Source: "example.exe"; DestDir: "{app}"

[Icons]
Name: "{group}\Example"; Filename: "{app}\example.exe"
Name: "{group}\Uninstall"; Filename: "{uninstallexe}"

Please, use Inno Setup! :)

13 thoughts on “Setup programs for Windows

  1. Argh. Your example implements one of my pet peeves w.r.t. windows: placing an uninstall menu item right next to the item used to start the application. Why would you put two diametrically opposed actions right next to each other when there is a standard place users can go to uninstall apps?

    Like

  2. Does InnoSetup run natively under Linux? That’s one huge plus for NSIS. In fact, its really the only reason I use NSIS for my projects. I don’t use Windows at all but I do maintain Windows ports of a few programs. I have my toolchains setup to cross-build Windows apps on my Linux system. The way NSIS works I can schedule the builds via cron, also.

    Like

  3. @James Henstridge:
    There are historical reasons, some old Windows versions do not have the applet used to uninstall software in the control panel, so you had to add the uninstall link in the start menu.

    Moreover the documentation written by Microsoft said that it was always a good thing to add the uninstaller to the start menu. However they also said other stupid things such as that it was a good thing to add deeply nested menus in the start menu, e.g. “All Programs -> FooSoftware -> FooSoftware Program Name -> ProgramName.exe”.

    @David L Norris:
    No, probably the problem is that it’s written in Delphi. However Inno Setup and the installers generated by Inno Setup run using wine.
    If there is interest someone could create a package using wine so you can use the command line compiler under Linux, but only on x86 machines.

    Like

  4. My experience is that wine requires X even for command line programs. There was a tty GDI driver for wine but that seems to have been removed some time ago. I also tried running wine from cron using a dummy X server but that didn’t work out.

    Like

  5. I cannot tell you why Alberto used NSIS but I can tell you when I went looking to replace the custom installer Abiword and used NSIS it was clearly and unambiguously Open Source and easy to find with plenty of easily reusable examples and clear documentation making things much easier than the horrible syntax might suggest. Even now Inno is not shouting out its Open Source credentials and Delphi syntax isn’t immediately appealing to everyone either.
    That NSIS came from Nullsoft and many other people were using it also gave a better confidence it would not be going anywhere because having the code is great and all but having to maintain and orphaned project no one else loves is not and there is always that risk.

    @James
    putting a destructive action so close to a productive action is not a particularly good idea as you say (yet we do it anyway with the Close button in the Window decorations). the uninstaller menu item should be avoided but those who insist on doing it should certainly try to put the main application launcher first and then put a shortcut items for other things to space it out from the destructive action of the uninstaller.

    Like

  6. Use MSI. This way windows admins can roll your apps out easier in a managed inviroment.

    I am pretty sure there is a python library that can help automatically build them for you.

    Please use MSI.

    Like

  7. This is why:

    arc@dopamine:~$ apt-cache search innosetup
    arc@dopamine:~$ apt-cache search ^nsis
    nsis – Nullsoft Scriptable Install System (modified for debian)
    arc@dopamine:~$

    I don’t want to spent my building packaging phase on windows, if you think inno setup is better, then I encourage you to do the releases instead of me 🙂

    Like

  8. There is only ONE proper way for delivering apps on Windows platform. It is MSI. It’s what the AD and SMS/MOM and 3rd party management tools use for deployments. If you don’t use MSI your software will not get mass deployed in many organizations. That has been Firefox’s #1 screw-up too. (Almost no major corporation will change to Firefox until there’s proper MSI package offered, the present 3rd party ones are too shady)

    MSI packages can be properly created using open source tools. They are also fit for interactive installations by the user. (Although slowish, it was really inteded for background installations and has a lot of transaction alike things going on.)

    Like

  9. Does InnoSetup support Unicode?

    Actually, one of the reasons Firefox moved to NSIS (from the legacy installer) was the support of Unicode for the installer.

    Like

Comments are closed.