From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search


Silent installer for Matlab 2010b. Simply using the command line to run the Matlab provided setup.exe along with the argument -inputfile followed by a preconfigured input file containing your license key, silent install option etc, just won't work. It seems that when the setup.exe is run, it spawns a new setup.exe (with another pid), the original setup.exe then exits, wpkg then sees this exit, tries to check the program has installed ok and fails. Meanwhile, the spawned setup.exe continues and installs Matlab.

To get around this, an Autoit script was written that is passed 4 arguments. The first one is the path to the setup.exe program. The second is the argument required to read in a log file. For Matlab this is '-inputfile'. The third is the path to the input file. The fourth is the time in seconds after which you want monitoring to start, give the 'real' setup.exe time to start. All the processes called 'setup.exe' are then searched for along with the command they are running. If one of the setup.exe's commands contain the string of the third argument, the config file, then its PID is obtained. In a While loop, the existance of this PID is checked, if it still exists, sleep, then re-check. If the PID doesn't exist, close the autoit exe, it is at this point that the install of Matlab would of finished and it is only now do we return pack the WPLG XML that will go and check the install has succeeded/failed.

Passing the arguments to the Autoit script allows multiple licensed toolboxes to be installed.

<?xml version="1.0" encoding="UTF-8"?>

<package id="matlab-main" name="Matlab R2010b - Main" revision="1.1" priority="15"  >
	<variable name="version" value="R2010b" />
	<variable name="domain" value="MATHS" />
	<check type="uninstall" condition="exists" path="MATLAB %version%" />
	<install cmd='%COMSPEC% /c if not exist c:\temp\ mkdir c:\temp' />	<!-- used for the matlab logs -->
	<install cmd='%COMSPEC% /c start "" /wait "\\%DOMAIN%\netlogon\scripts\matlab\matlab_install_wpkg.exe" "\\%DOMAIN%\wpkg7\server\WPKG-1.1.2\programs\math_progs\matlab-2010b\setup.exe" "%SOFTWARE%\math_progs\matlab_2010b_input.txt"' />
	<upgrade cmd='%COMSPEC% /c start "" /wait 2\\%DOMAIN%\netlogon\scripts\matlab\matlab_install_wpkg.exe" "\\%DOMAIN%\wpkg7\server\WPKG-1.1.2\programs\math_progs\matlab-2010b\setup.exe" "%SOFTWARE%\math_progs\matlab_2010b_input.txt"' />
	<remove cmd='%COMSPEC% /C if exist "%SYSTEMDRIVE%\matlab-%version%\uninstall\bin\win32\uninstall.exe" "%SOFTWARE%\math_progs\matlab_uninstall.bat" "%SYSTEMDRIVE%\matlab-%version%\uninstall\bin\win32\uninstall.exe" "%SOFTWARE%\math_progs\\matlab_2010b_uninstaller_input.txt"' />
	<remove cmd='%COMSPEC% /c rd /s /q "%SYSTEMDRIVE%\matlab-%version%"'>
		<exit code='any' />


Beware that, for versions older than R2012a, fully silent installations require "the appropriate version of Microsoft Visual C++ Redistributable 2005" (see for the details). If that version is missing, the installer tries its own vcredist_{x86,x64}.exe and waits endlessly for an EULA acceptance.

Is is prudent, then, to run vcredist_{x86,x64}.exe in silent mode before executing Matlab's setup.exe:

<install cmd='%SOFTWARE%\matlab2011b\bin\win32\vcredist_x86.exe /q:a'/>

(for the x86 version of R2011b)

Autoit code. Compile this into an exe

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Array.au3>
#include <Date.au3>

; *************************************************************************************************************
; Script to start the Matlab and Maple update install and keep them alive until their setup.exe program finishes.  This script is used by the Matlab
; and Maple WPKG program.  It's not as simple as making sure the process setup.exe is still running as there may already be a process running called
; setup.exe.  We need to look for the one that has the string matlab in the processes execute command line.  To make things harder, the matlab setup.exe
; seems to start with one pid for the exe, this then seems to spawn a new setup.exe with another pid so we can't simple launch the original setup.exe, note
; its pid and then keep an eye on it, we need to keep looking for the pid for the process setup.exe with the string matlab in the execute command.
; This is where the function _ProcessListProperties ( is used.
; A log file is made in the %TEMP% of the user running this script.  It's called [arg1's process.exe].log
; - April 2011
; *************************************************************************************************************

Opt("TrayMenuMode", 1) ; Default tray menu items (Script Paused/Exit) will not be shown.

If @Compiled = 1 Then
	If $CmdLine[0] < 4 Then
		MsgBox(32, "Usage", "KeepAlive WPKG Installer Usage:" & @CRLF & @CRLF & "For some installers (Java based), a program setup " & _
				"program exits before the install has finished.  This program stops the premature exiting until the installer " & _
				"has finished.  It does this by monitoring the PID of the installer and only exiting when the installer has finished.  Useful " & _
				"when installing a program with WPKG." & @CRLF & @CRLF & @ScriptName & " (path to programs' install program) (argument " & _
				"needed to include config file) (path to config file)  (time in seconds to wait before monitoring installer)" & @CRLF & _
				@CRLF & "E.g. " & @ScriptName & "  %LOGONSERVER%\wpkg7\server\WPKG-1.1.2\programs\math_progs\matlab-2010b\setup.exe  " & _
				"-inputFile  %LOGONSERVER%\wpkg7\server\WPKG-1.1.2\programs\math_progs\matlab_2010b_input.txt  5" & @CRLF & @CRLF & _
				"This script creates a log file in the users running this scripts Temp dir called {exe of 1st argument}_install.log" & @CRLF & @CRLF _
				 & "C. Mortimer 2011", 30)
		$install_prog = $CmdLine[1]
		$call_argument_wth = $CmdLine[2]
		$config_file = $CmdLine[3]
		$wait_time = $CmdLine[4] * 1000
	Exit ; not really going to be run without compiling it
;~ 	$install_prog = "c:\Program Files\Windows NT\Accessories\wordpad.exe"
;~ 	$call_argument_wth = "foo"
;~ 	$config_file = "wibble"
;~ 	$wait_time = 2 * 1000

Dim $oWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"), $commandline, $arg_found, $pid

$q = 1
$process_name = StringTrimLeft($install_prog, StringInStr($install_prog, "\", 0, -1))
$log = EnvGet("temp") & "\" & $process_name & "_install.log"	; delete the old log file
If FileGetSize ($log) > 5000000 Then FileCopy ($log, EnvGet("temp") & "\" & $process_name & "_install.old.log", 1)

$run_install = Run($install_prog & " " & $call_argument_wth & " " & $config_file) ; Run the installer...

_log("Now starting." & @CRLF & "* Program to run = '" & $install_prog & "'" & @CRLF & "* Argument required to call in config file ='" & _
		$call_argument_wth & "'," & @CRLF & "* Config file = '" & $config_file & "'" & @CRLF & "* Search string = '" & $install_prog & "'" & @CRLF & _
		"* Wait before monitoring = '" & $wait_time / 1000 & "s'.  [PID = '" & $run_install & "']")


While $q = 1
	$arg_found = 0
	$o_ColListOfProcesses = $oWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = '" & $process_name & "'")
	For $o_ObjProcess In $o_ColListOfProcesses
		$commandline = $o_ObjProcess.CommandLine
		$stringinstring = StringInStr($commandline, $config_file)
		If $stringinstring > 0 Then
			$arg_found = $o_ObjProcess.Handle	; set $arg_found to the PID

	If $arg_found > 0 Then
		_log($process_name & " still running...  [PID = '" & $arg_found & "']")
		ConsoleWrite($process_name & " is running with a PID of " & $arg_found & @CRLF)
		_log($process_name & " isn't running.")
		ConsoleWrite($process_name & " isn't running, ending" & @CRLF)
		$q = 2


Func _log($text)
	FileOpen(EnvGet("temp") & "\" & $process_name & "_install.log", 1) ; append to the log file
	FileWriteLine($log, $text & " [" & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "]")
EndFunc   ;==>_log

Removal of Matlab

To remove Matlab and/or Matlab toolboxes, you can't simply run the documented command line:

"%SYSTEMDRIVE%\matlab-%version%\uninstall\bin\win32\uninstall.exe" -inputfile "%SOFTWARE%\math_progs\\matlab_2010b_uninstaller_input.txt"

If you do, the uninstall.exe program will start, launch the uninstall gui (hidden from view of course so you've no idea what's going on) and sit there. To 'make it work', create a very simple batch file that accepts two arguments, one, the path the the uninstall.exe and the second, the path to the input file (copy of this input file is in {path to matlab}\uninstall\). Run this batch file as the <remove>.

@echo off
set config=%2

start "matlab" /wait %SOFTWARE% -inputFile %CONFIG%