Changes

Jump to: navigation, search

Maple

13,442 bytes added, 13:19, 15 April 2011
m
Created page with "=Maple= ==v14.00== I've added a 'chain' to install the v14.01 update package. <source lang="xml"> <?xml version="1.0" encoding="UTF-8"?> <packages> <package id="maple14" name..."
=Maple=

==v14.00==

I've added a 'chain' to install the v14.01 update package.

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

<package id="maple14" name="Maple 14" revision="1.2" reboot="false" priority="73">
<variable name="version" value="14"/>
<check type="uninstall" condition="exists" path="Maple %version% (Maple %version%)" />
<chain package-id="maple14.01" />

<install cmd='"%SOFTWARE%\math_progs\maple\Windows\Disk1\InstData\VM\Maple%version%WindowsInstaller.exe" -f "%SOFTWARE%\math_progs\maple.answer"' />

<upgrade cmd='"%PROGRAMFILES%\Maple %version%\uninstall\Uninstall Maple %version%.exe" -i silent' />
<upgrade cmd='"%SOFTWARE%\math_progs\maple\Windows\Disk1\InstData\VM\Maple%version%WindowsInstaller.exe" -f "%SOFTWARE%\math_progs\maple.answer"' />

<remove cmd='"%PROGRAMFILES%\Maple %version%\uninstall\Uninstall Maple %version%.exe" -i silent' />
<remove cmd='%COMSPEC% /c rd /s /q "%PROGRAMFILES%\Maple %version%"'>
<exit code='any' />
</remove>

</package>

</packages>
</source>

==v14.01 (update)==

There doesn't seem to be an uninstall for the update. Running the update exe with the argument '-f [path to an answer file containing only 'INSTALLER_UI=SILENT']' doesn't seem to work. To overcome this, the 'check' looks for a file. This file gets created as part of the <install> and is a copy of the exe maplew.exe. When this xml is first ran, the check will fail so the install will take place. First the file copy is make, then the 'Maple1401WindowsUpgrade.exe' is run. At uninstall time, the <remove> simply uninstalls the copied file therefore the removal of the XML will work and as the update is a chain of the main Maple install, this success will allow the main Maple to be uninstalled.

As for the install of Matlab, one 'feature' is that when the upgrade exe is run, it returns back to the command prompt before the update has finished. To overcome this, an Autoit script was created (below) to run the update exe and keep open until the PID of the update exe has really closed. The Autoit exe then exits, WPKG then does the check at the correct time.

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

<package id="maple14.01" name="Maple 14.01 Update" revision="1.2" reboot="false" priority="73">
<depends package-id="maple14" />
<variable name="domain" value="MATHSDOM" />
<variable name="version" value="14"/>
<variable name="update" value="01" />
<!--<check type="file" condition="versionequalto" path="%PROGRAMFILES%\Maple 14\bin.win\maple.exe" value="1.0.0.1" />-->
<check type="file" condition="exists" path="%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%" />

<!-- First make a backup of the original maplew.exe file. This is used for the <remove /> part of this file as there isn't
an uninstaller for the update therefore we need to uninstall something to make the <check /> work so that we can then uninstall
the main Maple program-->
<install cmd='%COMSPEC% /c copy /y "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe" "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%"' />
<!-- Now install the update... -->
<install cmd='%COMSPEC% /c start "" /wait "\\%DOMAIN%\netlogon\scripts\matlab_installer\matlab_install_wpkg.exe" "%SOFTWARE%\math_progs\maple\Maple1401WindowsUpgrade.exe" -f "%SOFTWARE%\math_progs\maple.answer" 4' />

<!-- First make a backup of the original maplew.exe file. This is used for the <remove /> part of this file as there isn't
an uninstaller for the update therefore we need to uninstall something to make the <check /> work so that we can then uninstall
the main Maple program-->
<upgrade cmd='%COMSPEC% /c copy /y "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe" "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%"' />
<upgrade cmd='%COMSPEC% /c start "" /wait "\\%DOMAIN%\netlogon\scripts\matlab_installer\matlab_install_wpkg.exe" "%SOFTWARE%\math_progs\maple\Maple1401WindowsUpgrade.exe" -f "%SOFTWARE%\math_progs\maple.answer" 4' />

<remove cmd='%COMSPEC% /c del /q "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%"' />

</package>

</packages>
</source>

==Autoit code. Compile this into an exe==

<pre>
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=matlab_install_wpkg.exe
#AutoIt3Wrapper_Change2CUI=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <File.au3>
#include <Array.au3>
#include <Date.au3>

; Script to start the Matlab install and keep alive until the setup.exe program finishes. This script is used by the Matlab 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 (http://www.autoitscript.com/forum/topic/70538-processlistproperties/) is used.

; C. Mortimer 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)
Exit
Else
$install_prog = $CmdLine[1]
$call_argument_wth = $CmdLine[2]
$config_file = $CmdLine[3]
$wait_time = $CmdLine[4] * 1000
EndIf
Else
Exit ; not really going to be run without compiling it
EndIf

$q = 1
$process_name = StringTrimLeft($install_prog, StringInStr($install_prog, "\", 0, -1))

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

$log = FileOpen(EnvGet("temp") & "\" & $process_name & "_install.log", 2) ; Open the log file deleting all existing data
FileWriteLine($log, "Now starting. Program to run = '" & $install_prog & "', argument required to call in config file ='" & $call_argument_wth & "'," & @CRLF & "config file = '" & $config_file & "', search string = '" & $install_prog & "', wait before monitoring = '" & $wait_time / 1000 & "s'. [PID = " & $run_install & "] [" & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "]")
FileClose($log)

Sleep($wait_time)

While $q = 1
$log = FileOpen(EnvGet("temp") & "\" & $process_name & "_install.log", 1) ; append to the log file
$avRET = _ProcessListProperties($process_name)
$array_search = _ArraySearch($avRET, $call_argument_wth, "", "", 0, 1)
If $array_search >= 0 Then
FileWriteLine($log, $process_name & " still running... [PID = " & $avRET[$array_search][1] & "] [" & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "]")
FileClose($log)
Else
FileWriteLine($log, "Now exiting, " & $process_name & " no long running. [" & @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN & ":" & @SEC & "]")
FileClose($log)
$q = 2
EndIf
Sleep(5000)
WEnd
Exit


;===============================================================================
; Function Name: _ProcessListProperties()
; Description: Get various properties of a process, or all processes
; Call With: _ProcessListProperties( [$Process [, $sComputer]] )
; Parameter(s): (optional) $Process - PID or name of a process, default is "" (all)
; (optional) $sComputer - remote computer to get list from, default is local
; Requirement(s): AutoIt v3.2.4.9+
; Return Value(s): On Success - Returns a 2D array of processes, as in ProcessList()
; with additional columns added:
; [0][0] - Number of processes listed (can be 0 if no matches found)
; [1][0] - 1st process name
; [1][1] - 1st process PID
; [1][2] - 1st process Parent PID
; [1][3] - 1st process owner
; [1][4] - 1st process priority (0 = low, 31 = high)
; [1][5] - 1st process executable path
; [1][6] - 1st process CPU usage
; [1][7] - 1st process memory usage
; [1][8] - 1st process creation date/time = "MM/DD/YYY hh:mm:ss" (hh = 00 to 23)
; [1][9] - 1st process command line string
; ...
; [n][0] thru [n][9] - last process properties
; On Failure: Returns array with [0][0] = 0 and sets @Error to non-zero (see code below)
; Author(s): PsaltyDS at http://www.autoitscript.com/forum
; Date/Version: 12/01/2009 -- v2.0.4
; Notes: If an integer PID or string process name is provided and no match is found,
; then [0][0] = 0 and @error = 0 (not treated as an error, same as ProcessList)
; This function requires admin permissions to the target computer.
; All properties come from the Win32_Process class in WMI.
; To get time-base properties (CPU and Memory usage), a 100ms SWbemRefresher is used.
;===============================================================================
Func _ProcessListProperties($Process = "", $sComputer = ".")
Local $sUserName, $sMsg, $sUserDomain, $avProcs, $dtmDate
Local $avProcs[1][2] = [[0, ""]], $n = 1

; Convert PID if passed as string
If StringIsInt($Process) Then $Process = Int($Process)

; Connect to WMI and get process objects
$oWMI = ObjGet("winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy, (Debug)}!\\" & $sComputer & "\root\cimv2")
If IsObj($oWMI) Then
; Get collection processes from Win32_Process
If $Process == "" Then
; Get all
$colProcs = $oWMI.ExecQuery("select * from win32_process")
ElseIf IsInt($Process) Then
; Get by PID
$colProcs = $oWMI.ExecQuery("select * from win32_process where ProcessId = " & $Process)
Else
; Get by Name
$colProcs = $oWMI.ExecQuery("select * from win32_process where Name = '" & $Process & "'")
EndIf

If IsObj($colProcs) Then
; Return for no matches
If $colProcs.count = 0 Then Return $avProcs

; Size the array
ReDim $avProcs[$colProcs.count + 1][10]
$avProcs[0][0] = UBound($avProcs) - 1

; For each process...
For $oProc In $colProcs
; [n][0] = Process name
$avProcs[$n][0] = $oProc.name
; [n][1] = Process PID
$avProcs[$n][1] = $oProc.ProcessId
; [n][2] = Parent PID
$avProcs[$n][2] = $oProc.ParentProcessId
; [n][3] = Owner
If $oProc.GetOwner($sUserName, $sUserDomain) = 0 Then $avProcs[$n][3] = $sUserDomain & "\" & $sUserName
; [n][4] = Priority
$avProcs[$n][4] = $oProc.Priority
; [n][5] = Executable path
$avProcs[$n][5] = $oProc.ExecutablePath
; [n][8] = Creation date/time
$dtmDate = $oProc.CreationDate
If $dtmDate <> "" Then
; Back referencing RegExp pattern from weaponx
Local $sRegExpPatt = "\A(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})(?:.*)"
$dtmDate = StringRegExpReplace($dtmDate, $sRegExpPatt, "$2/$3/$1 $4:$5:$6")
EndIf
$avProcs[$n][8] = $dtmDate
; [n][9] = Command line string
$avProcs[$n][9] = $oProc.CommandLine

; increment index
$n += 1
Next
Else
SetError(2); Error getting process collection from WMI
EndIf
; release the collection object
$colProcs = 0

; Get collection of all processes from Win32_PerfFormattedData_PerfProc_Process
; Have to use an SWbemRefresher to pull the collection, or all Perf data will be zeros
Local $oRefresher = ObjCreate("WbemScripting.SWbemRefresher")
$colProcs = $oRefresher.AddEnum($oWMI, "Win32_PerfFormattedData_PerfProc_Process" ).objectSet
$oRefresher.Refresh

; Time delay before calling refresher
Local $iTime = TimerInit()
Do
Sleep(20)
Until TimerDiff($iTime) >= 100
$oRefresher.Refresh

; Get PerfProc data
For $oProc In $colProcs
; Find it in the array
For $n = 1 To $avProcs[0][0]
If $avProcs[$n][1] = $oProc.IDProcess Then
; [n][6] = CPU usage
$avProcs[$n][6] = $oProc.PercentProcessorTime
; [n][7] = memory usage
$avProcs[$n][7] = $oProc.WorkingSet
ExitLoop
EndIf
Next
Next
Else
SetError(1); Error connecting to WMI
EndIf

; Return array
Return $avProcs
EndFunc ;==>_ProcessListProperties
</pre>

[[Category: Silent Installers]]

Navigation menu