What is Ninite?
Ninite is commercial software which installs and updates a variety of popular applications. The professional version as a commandline option and can be included in scripts. The professional version can integrate ninite with wpkg, so that we can use ninite for installing and patching common utilities, whilst using wpkg to install the more unusual or specific applications.
Obviously this is contrary to a pure open source approach of only using wpkg, though some system admins may find this a practical compromise.
 Overview of this example of how to use ninite with wpkg
- We run the installer as a nightly scheduled task, and build a cache of the results
- We create a wpkg package for each application which is installed using ninite. This package is run once only
- We run ninite with the "updateonly" option for all applications, to ensure that all relevant applications are kept up to date. This package is run at every boot.
- We have to parse the ninite log file to report to wpkg whether or not an installation or update failed or succeeded.
 Directory setup
- Create a directory called "ninite" in the %SOFTWARE% directory.
- Save your copy of NiniteOne.exe or NiniteProTrial.exe in %SOFTWARE%\ninite\
NiniteOne.exe is only available to Pro customers. This will almost certainly not work with the free version of ninite.exe
 Scheduled task to cache the installers
The following script is run as a scheduled task on a suitable server or other machine. The script should live in your %SOFTWARE%\ninite\ directory:
%~dp0NiniteOne.exe /freeze %~dp0niniteofflineinstaller.exe /cachepath %~dp0ninitecache /select ".NET 4" ".NET 4.5" ".NET" "7-Zip" "Citrix Receiver" "Classic Start" "Flash (IE)" "Google Drive" "Google Earth" "Java 7" "Java x64 7" "Java x64" "JDK 6" "Notepad++" "Paint.NET" Air CDBurnerXP Chrome FileZilla Firefox Flash GIMP Inkscape IrfanView Java JDK KeePass PDFCreator Picasa PuTTY Python Reader Shockwave Silverlight Spybot Steam TeamViewer TeraCopy TrueCrypt WebEx Winamp WinDirStat WinMerge WinSCP /silent .
This creates a directory called "ninitecache" which holds a offline cache of all the installers we require. It also creates a single executable "niniteofflineinstaller.exe", however this can be very large ~1.5Gb. As a result this exe is too slow to load sensibly. We only create it as a means of obtaining the cache directory.
 A wpkg package to install an individual application
Below is an example of a package which will install the application named in the appSelectName variable (in this case PDFCreator). The names used by the ninite commandline are given on this page. The various switches disable the application's own autoupdate features and prevent the installers creating shortcuts on the desktop or quicklaunch bar. For a full list of commandline options see this page.
<package id="pdfcreator" name='PDFCreator' revision="20130211.1" reboot="false" notify="false" execute="once" priority="10"> <variable name="appSelectName" value='PDFCreator' /> <variable name="ninitelogfilename" value='wpkg-ninite-%COMPUTERNAME%-%appSelectName%.log' /> <chain package-id="ninite-updater" /> <install cmd='%comspec% /C if exist %temp%\%ninitelogfilename% del %temp%\%ninitelogfilename%' timeout="15" ><exit code="0" /></install> <install cmd='%comspec% /C %SOFTWARE%\ninite\NiniteOne.exe /cachepath %SOFTWARE%\ninite\ninitecache /select %appSelectName% /silent %temp%\%ninitelogfilename% /allusers /disableshortcuts /disableautoupdate' timeout="600"><exit code="0" /></install> <install cmd='%comspec% /C %SOFTWARE%\ninite\testninitelogfiles.bat %temp%\%ninitelogfilename%' timeout="15" ><exit code="0" /></install> <upgrade include="install" /> <remove cmd='%comspec% /C %SOFTWARE%\ninite\NiniteOne.exe /cachepath %SOFTWARE%\ninite\ninitecache /select %appSelectName% /silent /uninstall'/> </package>
- This could probably be done more elegantly using wpkg package templates.
- For occasions where the appSelectName is not a valid file name (eg ".NET" including the quotes) the ninitelogfilename varible should be updated manually.
 A wpkg package which will update all relevant applications
This package will update all supported applications at every boot, whether or not they were originally installed by ninite. This is very handy to minimise the problem of users installing their own software and then never updating them.
<package id="ninite-updater" name="Ninite Updater" revision="20130210.3" reboot="false" notify="false" execute="always" priority="1"> <install cmd='%comspec% /C if exist %temp%\ninite-wpkg-%COMPUTERNAME%-updater.log del %temp%\ninite-wpkg-%COMPUTERNAME%-%appSelectName%.log' timeout="15" ><exit code="0" /></install> <install cmd='%comspec% /C %SOFTWARE%\ninite\NiniteOne.exe /cachepath %SOFTWARE%\ninite\ninitecache /disableshortcuts /disableautoupdate /updateonly /exclude TeamViewer FileZilla "Google Earth" /silent %temp%\ninite-wpkg-%COMPUTERNAME%-updater.log' timeout="600" > <exit code="0" /> </install> <install cmd='%comspec% /C %SOFTWARE%\ninite\testninitelogfiles.bat %temp%\ninite-wpkg-%COMPUTERNAME%-updater.log' timeout="15" ><exit code="0" /></install> <upgrade include="install" /> </package>
 A script to check the Ninite logs
Both of the packages above use a script "testninitelogfiles.bat" to parse the ninte log files and check for success or failure. Again this script should live in your %SOFTWARE%\ninite\ directory.
@echo off setlocal if [%1]== ( goto paramerror ) else ( set ninitelogfile="%~f1" ) :checklogfileexists if not exist %ninitelogfile% ( goto nonexistinglogfile ) :checkfirstline for /f "tokens=1" %%a in ('findstr /N /O /I /B /E /L "OK Partial" %ninitelogfile%') do set firstline=%%a ::echo %firstline% :: first check for the word "OK" as the first thing on the first line. If this is present then we assume that everything is OK and quit. if /I "%firstline%" EQU "1:0:OK" (goto reportok) :: next check for the word "Partial" as the first thing on the first line. If this is present then we do some more checks on the rest of the file if /I "%firstline%" EQU "1:0:Partial" (goto checkrestoffile) else (goto failfirstline) :checkrestoffile :: We use findstr again to search the rest fo the file. The /V switch means :: that we only return the lines of the log files with do not match our :: whitelist of good values, which are: :: "OK" or "Partial" matching both the begining and end of the first line :: "OK" or "Skipped (up to date)" matching the end of any subequent line :: The regular expression captures these conditions. for /f "tokens=*" %%g in ('findstr /V /N /I /E /R "OK$ ^Partial$ Skipped.(up.to.date)$ Skipped.(installed.version.is.newer)$" %ninitelogfile%') do set result="%%g" :: If there are any values in this variable then the log file has failed if not [%result%] ==  ( goto failrestoffile ) :: This is only reached is everything is OK :reportok ::echo reportok exit /B 0 :paramerror ::echo paramerror exit /B 1 :nonexistinglogfile ::nonexistinglogfile exit /B 2 :failfirstline ::echo failfirstline exit /B 3 :failrestoffile ::echo failrestoffile exit /B 4