Automating CPack/NSIS-built Installers Silently on Windows

October 25, 2011

The CMake Win32 installer is built with NSIS, and as such, it supports some of the standard command line arguments that all such NSIS built installers do. If you build Windows installers for your project using NSIS and CPack, you can use this information with your installers, too.

Specifically, you can write a silent automatic install command line like so:

  “C:\full\path\to\cmake-2.8.5-win32-x86.exe” /S /D=C:\path\to\install\to\with\no\spaces

Furthermore, you may silently call the uninstaller like so:

  C:\path\to\install\to\with\no\spaces\Uninstall.exe /S

Importantly, (I’ve determined this empirically by experiment, so I may be stating things overly strictly here, but I don’t think so….) you must have:

  • Most importantly, admin privileges — this needs to be run in a “Run as Admin” type setting, or else Windows will prompt the user to see if it’s ok to run an installer/uninstaller
  • the “/S” indicates “silent” and means do not show the gui for the installer/uninstaller
  • the “/D” must be the last argument you pass to the installer, indicating the root directory into which to install
  • Everything after the “/D=” should name the full path to a directory with “\” separator characters, (not with “/”) *and* with no spaces in it. It is still possible in Windows to construct a valid 8.3 old-school DOS name for any file or directory, and if you need to install it in a path that does have spaces in it for real, then you’ll have to construct the short name equivalent to pass with /D=

This approach definitely works with the latest release, CMake 2.8.6, and should work as far back as 2.8.0.

Since we have not documented this feature of the Windows installer anywhere, I thought this would be good fodder for a blog entry.

Ping me: leave a comment here if you use it to do something cool.

1 comment to Automating CPack/NSIS-built Installers Silently on Windows

Leave a Reply