Run Ninite Pro with Nice Logs from MAXfocus
I’ve deployed Ninite Pro to update non-Windows applications on computers that I manage. I’m running it in silent mode but I wanted some decent logging so I can review what it did. This is especially useful when run from the MAXfocus dashboard as a Scheduled Task: the output is visible from the dashboard.
The script takes two parameters:
Param 1 Path to local or network copy of NiniteOne.exe.
Param 2 Optional path to a NiniteDownloads cache. This can be on a network share, in which case the MAXfocus agent must run as a user with network access (not as the default SYSTEM account). Defaults to %temp%\NiniteDownloads if not specified. Fails if not accessible.
Example (type on one line):
NiniteUpdate.cmd "%SystemDrive%\Scripts\Helpers" "\\SRV01\NiniteDownloads"
Behavior
Ninite is run three times: first in /audit mode, then in /updateonly mode, then again in /audit mode. Output is written to the NiniteUpdateSummary.log file in the same folder as the script. “Not installed” messages are omitted, so you get a nice summary of what is installed. When the script completes, the NiniteUpdateSummary.log file is written to stdout (which is what is displayed in the MAXfocus dashboard). Additionally, the full result of the final audit (including the “Not installed” messages) is saved as NiniteAuditAfterUpdate.log.
There is a hard-coded variable in the script called CommonParams that excludes Microsoft programs (I use Microsoft Update for those), some other programs that were not updating, and TeamViewer (since that update can clobber the MAXfocus Take Control function). I also set it to /disableshortcuts. You may want to adjust these parameters and exclusions; see the Ninite command-line switch reference and their list of apps.
Sample Output
If you run this script from MAXfocus, you’ll want to run it as an automated task—it’s too long to run as a DSC check. I let it run for an hour. After it completes, the Automated Task window will look like this:
If you scroll in the Details area, you’ll see the full output:
--------------------------------------------------------------
Ninite -Audit before updating - Tue 12/16/2014 - 4:00:51.31
Partial
Air : OK -15.0.0.356
Firefox : OK - 34.0.5
Flash : Update - 15.0.0.246 ->16.0.0.235
Reader : Update - 10.1.7 -> 11.0.10
Skype : Update -6.22.0.107 -> 7.0.0.102
--------------------------------------------------------------
Ninite - Update Only - Tue 12/16/2014 - 4:00:59.83
OK
Flash :OK
Skype : OK
Reader :OK
--------------------------------------------------------------
Ninite- Audit after updating - Tue 12/16/2014 - 4:07:55.61
OK
Air : OK -15.0.0.356
Firefox : OK - 34.0.5
Flash : OK - 16.0.0.235
Reader : OK -11.0.10
Skype : OK -7.0.0.102
--------------------------------------------------------------
Exiting with ExitCode 0
The Script
Save this as NiniteUpdate.cmd. For easier reading and editing, open it in Notepad++. See comments in the script re. various updates since its initial release.
@echo offREM Run Ninite /updateonly on the local computer, optionally caching to local or network path.REMREM Copyright 2015 by Mark Berry, MCB Systems, www.mcbsys.com. REM Free for personal or commercial use. May not be sold.REM No warranties. Use at your own risk.REMREM Param 1: Path to local or network copy of NiniteOne.exe. REM Path only; assumes "NiniteOne.exe" for program name.REMREM Param 2: Path to NiniteDownloads cache. Can be on a network share. Defaults REM to %temp%\NiniteDownloads if not specified. Fails if not accessible.REMREM Assumes you have administrative permissions on the local PC.REMREM Creates/replaces NiniteUpdateSummary.log in %ProgramPath%.REMREM 12/11/2014 Initial script.REMREM 12/13/2014 Modify to create and save NiniteUpdateSummary.log as combined log file.REM Individual Ninite runs write to NiniteTemp.log, deleted after use.REM Final audit saved to NiniteAuditAfterUpdate.log.REMREM 12/16/2014 Add exclusions for Avast and AVG (can't update security software), CCleaner REM (vendor doesn't allow update) and Messenger (discontinued).REMREM 01/31/2015 Exclude ".NET 3.5.2", a new Microsoft program.REMREM 03/16/2015 Print program and cache path at beginning of NiniteUpdateSummary.log.REMREM 04/02/2015 Show parameters in log. REM Don't try to write to log if log path (%ProgramPath%) not found.REMREM 04/27/2015 - Fix bug that was putting cache in C:\Program Files (x86)\Advanced Monitoring Agent\scripts\-logfileREM folder when no cache location was specified and script was run from Max RM.REM - Set default cache location to NiniteOne.exe folder (param 1) + \NiniteDownloads.REMREM 11/04/2015 - Max RM agent 9.12.3 introduced a bug that encloses parameters in single quotation marks if theyREM were passed in double quotation marks. Strip out single quotation marks around parameters.REM ===========================================================================================REM Set up variablesREM ===========================================================================================REM This script can be adapted to run another program by modifying the next two linesset ProgramExe=NiniteOne.exeREM Exit with 0; exceptions belowset /A exitcode=0REM ===========================================================================================REM Check for parametersREM ===========================================================================================if ###%1###==###### goto NoParam1goto Param1Found:NoParam1echo.echo Missing parameter(s)echo.echo Usage: NiniteUpdate.cmd PathToNinite [NiniteDownloadsCache]echo.echo Example:echo.echo NiniteUpdate.cmd "C:\Scripts\Helpers" "\\SRV01\NiniteDownloads"echo.set /A exitcode=1001goto End:Param1FoundREM Strip double quotation marks, if any, from parameterset ProgramPath=%~1REM Now strip single quotation marks, if any, added by Max RM caller bug. REM See http://ss64.com/nt/syntax-dequote.html.set ProgramPath=###%ProgramPath%###set ProgramPath=%ProgramPath:'###=%set ProgramPath=%ProgramPath:###'=%set ProgramPath=%ProgramPath:###=%if ###%2###==###### goto NoParam2REM Max RM adds a -logfile parameter as the last parameter. Ignore that.if ###%2###==###-logfile### goto NoParam2goto Param2Found:NoParam2set CachePath=%ProgramPath%\NiniteDownloadsgoto EchoParams:Param2FoundREM Strip double quotation marks, if any, from parameterset CachePath=%~2REM Now strip single quotation marks, if any, added by Max RM caller bug. REM See http://ss64.com/nt/syntax-dequote.html.set CachePath=###%CachePath%###set CachePath=%CachePath:'###=%set CachePath=%CachePath:###'=%set CachePath=%CachePath:###=%:EchoParamsREM ===========================================================================================REM Echo parsed parametersREM ===========================================================================================REM echo ProgramPath: %ProgramPath%REM echo ProgramExe: %ProgramExe%REM echo CachePath: %CachePath%REM echo.REM ===========================================================================================REM Check for program pathREM ===========================================================================================if exist "%ProgramPath%" goto ProgramPathExistsecho Program path "%ProgramPath%" does not exist. Exiting.set /A exitcode=1002goto End:ProgramPathExistsREM ===========================================================================================REM Check for program executableREM ===========================================================================================if exist "%ProgramPath%\%ProgramExe%" goto ProgramExistsecho Program executable "%ProgramPath%\%ProgramExe%" does not exist. Exiting.set /A exitcode=1003goto End:ProgramExistsREM ===========================================================================================REM Check for cache pathREM ===========================================================================================REM First try to create it if it doesn't existif not exist "%CachePath%" md "%CachePath%"REM If it still doesn't exist, e.g. if it's on an inaccessible network share, failif exist "%CachePath%" goto CachePathExistsecho Downloads cache path "%CachePath%" does not exist and could not create it. Exiting.set /A exitcode=1004goto End:CachePathExistsREM ===========================================================================================REM Run Ninite three times with various parametersREM ===========================================================================================set CommonParams=/silent "%ProgramPath%\NiniteTemp.log" /disableshortcuts /exclude ".NET" ".NET 3.5" ".NET 4" ".NET 4.5" ".NET 4.5.1" ".NET 4.5.2" Avast AVG CCleaner Essentials Messenger Office OneDrive OpenOffice Silverlight SkyDrive TeamViewerset CacheParam=/cachepath "%CachePath%"REM Send all output to NiniteUpdateSummary.log file. First redirect overwrites previous log; the rest append.set LogFullPath=%ProgramPath%\NiniteUpdateSummary.logecho NiniteUpdate.cmd > "%LogFullPath%"echo. >> "%LogFullPath%"echo Program: %ProgramPath%\%ProgramExe% >> "%LogFullPath%"echo Cache param: %CacheParam% >> "%LogFullPath%"echo Common params: %CommonParams% >> "%LogFullPath%"echo Log file: %LogFullPath% >> "%LogFullPath%"echo. >> "%LogFullPath%"echo -------------------------------------------------------------- >> "%LogFullPath%"echo Ninite - /audit before updating - %date% - %time% >> "%LogFullPath%"echo. >> "%LogFullPath%""%ProgramPath%\%ProgramExe%" /audit %CommonParams% %CacheParam%set /a errorcode=%errorlevel%if %errorcode% EQU 0 goto Continue1echo Running first %ProgramExe% /audit failed with ErrorLevel %errorcode%. Exiting.set /A exitcode=1100+%errorcode%goto PrintLogAndEnd:Continue1REM Print lines that do NOT contain the string ": Not installed"type "%ProgramPath%\NiniteTemp.log" | find /V ": Not installed" >> "%LogFullPath%"del "%ProgramPath%\NiniteTemp.log"echo. >> "%LogFullPath%"echo -------------------------------------------------------------- >> "%LogFullPath%"echo Ninite - /updateonly - %date% - %time% >> "%LogFullPath%"echo. >> "%LogFullPath%""%ProgramPath%\%ProgramExe%" /updateonly %CommonParams% %CacheParam%set /a errorcode=%errorlevel%if %errorcode% EQU 0 goto Continue2echo Running %ProgramExe% /updateonly failed with ErrorLevel %errorcode%. Exiting.set /A exitcode=1100+%errorcode%goto PrintLogAndEnd:Continue2type "%ProgramPath%\NiniteTemp.log" >> "%LogFullPath%"del "%ProgramPath%\NiniteTemp.log"echo. >> "%LogFullPath%"echo -------------------------------------------------------------- >> "%LogFullPath%"echo Ninite - /audit after updating - %date% - %time% >> "%LogFullPath%"echo. >> "%LogFullPath%""%ProgramPath%\%ProgramExe%" /audit %CommonParams% %CacheParam%set /a errorcode=%errorlevel%if %errorcode% EQU 0 goto Continue3echo Running second %ProgramExe% /audit failed with ErrorLevel %errorcode%. Exiting.set /A exitcode=1100+%errorcode%goto PrintLogAndEnd:Continue3type "%ProgramPath%\NiniteTemp.log" | find /V ": Not installed" >> "%LogFullPath%"REM Save final full log as NiniteAuditAfterUpdate.log (delete old audit first)del "%ProgramPath%\NiniteAuditAfterUpdate.log"ren "%ProgramPath%\NiniteTemp.log" "NiniteAuditAfterUpdate.log":PrintLogAndEndecho. >> "%LogFullPath%"echo -------------------------------------------------------------- >> "%LogFullPath%"echo. >> "%LogFullPath%"REM Type log to stdout so it will appear in Max RM dashboardtype "%LogFullPath%"echo Exiting with ExitCode %exitcode% >> "%LogFullPath%":EndREM Display ExitCode in stdout even if log file not availableecho Exiting with ExitCode %exitcode%exit /b %exitcode% |