Difference between revisions of "Maple"
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...") |
|||
Line 13: | Line 13: | ||
<check type="uninstall" condition="exists" path="Maple %version% (Maple %version%)" /> | <check type="uninstall" condition="exists" path="Maple %version% (Maple %version%)" /> | ||
<chain package-id="maple14.01" /> | <chain package-id="maple14.01" /> | ||
+ | <variable name="path_reorder_exe" value="\\mathsdom\netlogon\scripts\system_path_reorder\path_reorder.exe" /> | ||
<install cmd='"%SOFTWARE%\math_progs\maple\Windows\Disk1\InstData\VM\Maple%version%WindowsInstaller.exe" -f "%SOFTWARE%\math_progs\maple.answer"' /> | <install cmd='"%SOFTWARE%\math_progs\maple\Windows\Disk1\InstData\VM\Maple%version%WindowsInstaller.exe" -f "%SOFTWARE%\math_progs\maple.answer"' /> | ||
+ | <install cmd='"%path_reorder_exe%" begin system32 env' /> | ||
<upgrade cmd='"%PROGRAMFILES%\Maple %version%\uninstall\Uninstall Maple %version%.exe" -i silent' /> | <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"' /> | <upgrade cmd='"%SOFTWARE%\math_progs\maple\Windows\Disk1\InstData\VM\Maple%version%WindowsInstaller.exe" -f "%SOFTWARE%\math_progs\maple.answer"' /> | ||
+ | <upgrade cmd='"%path_reorder_exe%" begin system32 env' /> | ||
<remove cmd='"%PROGRAMFILES%\Maple %version%\uninstall\Uninstall Maple %version%.exe" -i silent' /> | <remove cmd='"%PROGRAMFILES%\Maple %version%\uninstall\Uninstall Maple %version%.exe" -i silent' /> | ||
<remove cmd='%COMSPEC% /c rd /s /q "%PROGRAMFILES%\Maple %version%"'> | <remove cmd='%COMSPEC% /c rd /s /q "%PROGRAMFILES%\Maple %version%"'> | ||
+ | <exit code='any' /> | ||
+ | </remove> | ||
+ | <remove cmd='%COMSPEC% /c rd /s /q "%SYSTEMDRIVE%\watcom-1.3"'> | ||
<exit code='any' /> | <exit code='any' /> | ||
</remove> | </remove> | ||
Line 44: | Line 50: | ||
<variable name="version" value="14"/> | <variable name="version" value="14"/> | ||
<variable name="update" value="01" /> | <variable name="update" value="01" /> | ||
+ | <variable name="path_reorder_exe" value="\\mathsdom\netlogon\scripts\system_path_reorder\path_reorder.exe" /> | ||
<!--<check type="file" condition="versionequalto" path="%PROGRAMFILES%\Maple 14\bin.win\maple.exe" value="1.0.0.1" />--> | <!--<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%" /> | <check type="file" condition="exists" path="%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%" /> | ||
Line 53: | Line 60: | ||
<!-- Now install the 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' /> | <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' /> | ||
+ | <install cmd='"%path_reorder_exe%" begin system32 env' /> | ||
<!-- First make a backup of the original maplew.exe file. This is used for the <remove /> part of this file as there isn't | <!-- First make a backup of the original maplew.exe file. This is used for the <remove /> part of this file as there isn't | ||
Line 59: | Line 67: | ||
<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 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' /> | <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' /> | ||
+ | <upgrade cmd='"%path_reorder_exe%" begin system32 env' /> | ||
<remove cmd='%COMSPEC% /c del /q "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%"' /> | <remove cmd='%COMSPEC% /c del /q "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%"' /> | ||
Line 267: | Line 276: | ||
Return $avProcs | Return $avProcs | ||
EndFunc ;==>_ProcessListProperties | EndFunc ;==>_ProcessListProperties | ||
+ | </pre> | ||
+ | |||
+ | ==System %PATH% re-order, Maple install screws it up== | ||
+ | |||
+ | When Maple is installed, it adds to the system %PATH% (C:\watcom-1.3\binnt;C:\watcom-1.3\binw). Normally this isn't a problem but for Maple it is as Maple installed a command sc.exe. Windows also has an sc.exe command for controlling services. Maple adds its additions to the beginning of %PATH% therefore when you try to change/add/delete a Windows service with sc, you get an error like: | ||
+ | |||
+ | <pre> | ||
+ | DOS/32A -- Protected Mode Run-time Version 7.2 | ||
+ | Copyright (C) Supernar Systems, Ltd. 1996-2002 | ||
+ | SC/32A fatal: DOS/32A environment variable is not set up properly | ||
+ | You need to reinstall DOS/32 Advanced DOS Extender on this computer | ||
+ | </pre> | ||
+ | |||
+ | This is because the Maple sc.exe is trying to run. To overcome this, another Autoit exe is ran (path_reorder.exe) after maple has installed to arrange the order of %PATH% and write the change to the %PATH% registry key that will get read in at next login. In the XML above, I've sorted %PATH% with anything with *system32% to be placed at the beginning of the %PATH% line. path_reorder.exe allows you to move all matches of the search string to the beginning or the end of %PATH% or to delete them from %PATH%. It also reads %PATH% from the environment variable or by reading the registry value. | ||
+ | |||
+ | <pre> | ||
+ | #Region ;**** Directives created by AutoIt3Wrapper_GUI **** | ||
+ | #AutoIt3Wrapper_Outfile=path_reorder.exe | ||
+ | #AutoIt3Wrapper_Res_Fileversion=0.0.0.14 | ||
+ | #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y | ||
+ | #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** | ||
+ | #include <Array.au3> | ||
+ | |||
+ | ; *********************************************************************************************************************** | ||
+ | ; | ||
+ | ; Script to remove from or move a requested search string to the end or to the beginning of the %PATH% system variable registry entry. | ||
+ | ; A log out and in is required to pick up the change (unless anyone else knows how to do this 'on the fly' | ||
+ | ; | ||
+ | ; C.Mortimer@damtp.cam.ac.uk April 2011 | ||
+ | ; | ||
+ | ; *********************************************************************************************************************** | ||
+ | |||
+ | If $Cmdline[0] < 3 Then | ||
+ | _help() | ||
+ | Exit | ||
+ | Else | ||
+ | $arg1 = StringLower($Cmdline[1]) | ||
+ | $string2search4 = StringLower($Cmdline[2]) | ||
+ | $env_or_reg = StringLower($Cmdline[3]) | ||
+ | EndIf | ||
+ | |||
+ | If ($arg1 = "remove") OR ($arg1 = "end") OR ($arg1 = "begin") Then | ||
+ | If ($env_or_reg = "env") OR ($env_or_reg = "reg") Then | ||
+ | ; | ||
+ | Else | ||
+ | _help() | ||
+ | Exit | ||
+ | EndIf | ||
+ | Else | ||
+ | _help() | ||
+ | Exit | ||
+ | EndIf | ||
+ | |||
+ | $reg_key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" | ||
+ | If $env_or_reg = "env" Then | ||
+ | $path_env_or_reg = EnvGet("PATH") | ||
+ | ElseIf $env_or_reg = "reg" Then | ||
+ | $path_env_or_reg = RegRead($reg_key, "Path") | ||
+ | EndIf | ||
+ | |||
+ | $path_array = StringSplit($path_env_or_reg, ";") | ||
+ | |||
+ | $array_search = _ArraySearch($path_array, $string2search4, "", "", "", 1) | ||
+ | |||
+ | If $arg1 = "end" Then ; move to the end section | ||
+ | $r = 0 | ||
+ | $log = "" | ||
+ | For $i = 1 To $path_array[0] - 1 Step 1 | ||
+ | If StringInStr($path_array[$i], $string2search4) Then | ||
+ | Do | ||
+ | If StringInStr($path_array[$path_array[0] - $r], $string2search4) Then | ||
+ | $log = $log & "," & $path_array[0] - $r & "," & $i ; make a note of the array elements already swapped, we don't want to swap these again. | ||
+ | $r = $r + 1 | ||
+ | EndIf | ||
+ | Until StringInStr($path_array[0] - $r, $string2search4) = 0 | ||
+ | $log = $log & "," & $r ; make a note of the array element number | ||
+ | |||
+ | If StringInStr($log, $i) Then | ||
+ | ;~ ConsoleWrite("ALL READY SWAPPED" & @CRLF) | ||
+ | Else | ||
+ | $log = $log & "," & $path_array[0] - $r & "," & $i ; make a note of the array elements already swapped, we don't want to swap these again. | ||
+ | _ArraySwap($path_array[$i], $path_array[$path_array[0] - $r]) | ||
+ | $r = $r + 1 | ||
+ | EndIf | ||
+ | EndIf | ||
+ | Next | ||
+ | ElseIf $arg1 = "begin" Then ; move to the beginning section | ||
+ | $r = 0 | ||
+ | $log = "" | ||
+ | For $i = $path_array[0] To 1 Step -1 | ||
+ | If StringInStr($path_array[$i], $string2search4) Then | ||
+ | Do ; lets work out the next incrementing array NOT containing our search string | ||
+ | If StringInStr($path_array[1 + $r], $string2search4) Then | ||
+ | $log = $log & "," & $r ; make a note of the array element number | ||
+ | $r = $r + 1 | ||
+ | EndIf | ||
+ | Until StringInStr($path_array[1 + $r], $string2search4) = 0 | ||
+ | $log = $log & "," & $r ; make a note of the array element number | ||
+ | |||
+ | If StringInStr($log, $i) Then | ||
+ | ;~ ConsoleWrite("ALL READY SWAPPED" & @CRLF) | ||
+ | Else | ||
+ | _ArraySwap($path_array[$i], $path_array[1 + $r]) | ||
+ | $r = $r + 1 | ||
+ | EndIf | ||
+ | EndIf | ||
+ | Next | ||
+ | ElseIf $arg1 = "remove" Then ; remove from the PATH | ||
+ | Do | ||
+ | $array_search = _ArraySearch($path_array, $string2search4, "", "", "", 1) | ||
+ | _ArrayDelete($path_array, $array_search) | ||
+ | Until _ArraySearch($path_array, $string2search4, "", "", "", 1) = -1 | ||
+ | Else | ||
+ | ; | ||
+ | EndIf | ||
+ | |||
+ | $new_path = _ArrayToString($path_array, ";", 1) | ||
+ | If $path_env_or_reg = $new_path Then | ||
+ | ; | ||
+ | Else | ||
+ | RegWrite($reg_key, "Path_pre_reorder", "REG_EXPAND_SZ", $path_env_or_reg) | ||
+ | If StringLeft($new_path, 1) = ";" Then $new_path = StringTrimLeft($new_path, 1) | ||
+ | RegWrite($reg_key, "Path", "REG_EXPAND_SZ", $new_path) | ||
+ | ConsoleWrite($new_path & @CRLF) | ||
+ | EndIf | ||
+ | |||
+ | Func _help() | ||
+ | ConsoleWrite(@CRLF & @CRLF & "Usage" & @CRLF & @CRLF & "Script to be used by WPKG to reorder/remove items out of the System PATH setting." & @CRLF & @CRLF & _ | ||
+ | "Three arguments are required. The first argument is either 'remove', 'end' or 'begin'. The second argument is the string, full or partical, of " & _ | ||
+ | "the item you want to remove, move to the end of the 'PATH' string or move to the beginning of the path string. Any parts of the existing 'PATH', " & _ | ||
+ | "semi-colon seperated, matching the second argument will be deleted/moved. The third is either 'env' or 'reg'. 'env' = read in and manipulate " & _ | ||
+ | "the 'PATH' environment variable. 'reg' reads in the subkey 'PATH' registry entry at HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\" & _ | ||
+ | "Environment." & @CRLF & @CRLF & "This script returns the new path to the cmd line and sets the registry subkey. The 'PATH' is read in at next login." & _ | ||
+ | @CRLF & @CRLF & "E.g." & @CRLF & @ScriptName & " remove miktex env = remove any parts of the environment variable 'PATH' with *miktex* in." & _ | ||
+ | @CRLF & @CRLF & @ScriptName & " end miktex reg = move any parts of the 'PATH' registry subkey with *miktex* to the end of the " & _ | ||
+ | " registry 'PATH' subkey" & @CRLF & @CRLF & @ScriptName & " begin miktex env = move any parts of the environment variable 'PATH' with *miktex* to the " & _ | ||
+ | "beginning of the registry 'PATH' subkey" & @CRLF & @CRLF & _ | ||
+ | "C. Mortimer April 2011" & @CRLF) | ||
+ | EndFunc ;==>_help | ||
</pre> | </pre> | ||
[[Category: Silent Installers]] | [[Category: Silent Installers]] |
Latest revision as of 10:53, 21 April 2011
Contents
Maple
v14.00
I've added a 'chain' to install the v14.01 update package.
<?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" />
<variable name="path_reorder_exe" value="\\mathsdom\netlogon\scripts\system_path_reorder\path_reorder.exe" />
<install cmd='"%SOFTWARE%\math_progs\maple\Windows\Disk1\InstData\VM\Maple%version%WindowsInstaller.exe" -f "%SOFTWARE%\math_progs\maple.answer"' />
<install cmd='"%path_reorder_exe%" begin system32 env' />
<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"' />
<upgrade cmd='"%path_reorder_exe%" begin system32 env' />
<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>
<remove cmd='%COMSPEC% /c rd /s /q "%SYSTEMDRIVE%\watcom-1.3"'>
<exit code='any' />
</remove>
</package>
</packages>
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.
<?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" />
<variable name="path_reorder_exe" value="\\mathsdom\netlogon\scripts\system_path_reorder\path_reorder.exe" />
<!--<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' />
<install cmd='"%path_reorder_exe%" begin system32 env' />
<!-- 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' />
<upgrade cmd='"%path_reorder_exe%" begin system32 env' />
<remove cmd='%COMSPEC% /c del /q "%PROGRAMFILES%\Maple %version%\bin.win\maplew.exe.%version%.%update%"' />
</package>
</packages>
Autoit code. Compile this into an exe
#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
System %PATH% re-order, Maple install screws it up
When Maple is installed, it adds to the system %PATH% (C:\watcom-1.3\binnt;C:\watcom-1.3\binw). Normally this isn't a problem but for Maple it is as Maple installed a command sc.exe. Windows also has an sc.exe command for controlling services. Maple adds its additions to the beginning of %PATH% therefore when you try to change/add/delete a Windows service with sc, you get an error like:
DOS/32A -- Protected Mode Run-time Version 7.2 Copyright (C) Supernar Systems, Ltd. 1996-2002 SC/32A fatal: DOS/32A environment variable is not set up properly You need to reinstall DOS/32 Advanced DOS Extender on this computer
This is because the Maple sc.exe is trying to run. To overcome this, another Autoit exe is ran (path_reorder.exe) after maple has installed to arrange the order of %PATH% and write the change to the %PATH% registry key that will get read in at next login. In the XML above, I've sorted %PATH% with anything with *system32% to be placed at the beginning of the %PATH% line. path_reorder.exe allows you to move all matches of the search string to the beginning or the end of %PATH% or to delete them from %PATH%. It also reads %PATH% from the environment variable or by reading the registry value.
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Outfile=path_reorder.exe #AutoIt3Wrapper_Res_Fileversion=0.0.0.14 #AutoIt3Wrapper_Res_FileVersion_AutoIncrement=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> ; *********************************************************************************************************************** ; ; Script to remove from or move a requested search string to the end or to the beginning of the %PATH% system variable registry entry. ; A log out and in is required to pick up the change (unless anyone else knows how to do this 'on the fly' ; ; C.Mortimer@damtp.cam.ac.uk April 2011 ; ; *********************************************************************************************************************** If $Cmdline[0] < 3 Then _help() Exit Else $arg1 = StringLower($Cmdline[1]) $string2search4 = StringLower($Cmdline[2]) $env_or_reg = StringLower($Cmdline[3]) EndIf If ($arg1 = "remove") OR ($arg1 = "end") OR ($arg1 = "begin") Then If ($env_or_reg = "env") OR ($env_or_reg = "reg") Then ; Else _help() Exit EndIf Else _help() Exit EndIf $reg_key = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" If $env_or_reg = "env" Then $path_env_or_reg = EnvGet("PATH") ElseIf $env_or_reg = "reg" Then $path_env_or_reg = RegRead($reg_key, "Path") EndIf $path_array = StringSplit($path_env_or_reg, ";") $array_search = _ArraySearch($path_array, $string2search4, "", "", "", 1) If $arg1 = "end" Then ; move to the end section $r = 0 $log = "" For $i = 1 To $path_array[0] - 1 Step 1 If StringInStr($path_array[$i], $string2search4) Then Do If StringInStr($path_array[$path_array[0] - $r], $string2search4) Then $log = $log & "," & $path_array[0] - $r & "," & $i ; make a note of the array elements already swapped, we don't want to swap these again. $r = $r + 1 EndIf Until StringInStr($path_array[0] - $r, $string2search4) = 0 $log = $log & "," & $r ; make a note of the array element number If StringInStr($log, $i) Then ;~ ConsoleWrite("ALL READY SWAPPED" & @CRLF) Else $log = $log & "," & $path_array[0] - $r & "," & $i ; make a note of the array elements already swapped, we don't want to swap these again. _ArraySwap($path_array[$i], $path_array[$path_array[0] - $r]) $r = $r + 1 EndIf EndIf Next ElseIf $arg1 = "begin" Then ; move to the beginning section $r = 0 $log = "" For $i = $path_array[0] To 1 Step -1 If StringInStr($path_array[$i], $string2search4) Then Do ; lets work out the next incrementing array NOT containing our search string If StringInStr($path_array[1 + $r], $string2search4) Then $log = $log & "," & $r ; make a note of the array element number $r = $r + 1 EndIf Until StringInStr($path_array[1 + $r], $string2search4) = 0 $log = $log & "," & $r ; make a note of the array element number If StringInStr($log, $i) Then ;~ ConsoleWrite("ALL READY SWAPPED" & @CRLF) Else _ArraySwap($path_array[$i], $path_array[1 + $r]) $r = $r + 1 EndIf EndIf Next ElseIf $arg1 = "remove" Then ; remove from the PATH Do $array_search = _ArraySearch($path_array, $string2search4, "", "", "", 1) _ArrayDelete($path_array, $array_search) Until _ArraySearch($path_array, $string2search4, "", "", "", 1) = -1 Else ; EndIf $new_path = _ArrayToString($path_array, ";", 1) If $path_env_or_reg = $new_path Then ; Else RegWrite($reg_key, "Path_pre_reorder", "REG_EXPAND_SZ", $path_env_or_reg) If StringLeft($new_path, 1) = ";" Then $new_path = StringTrimLeft($new_path, 1) RegWrite($reg_key, "Path", "REG_EXPAND_SZ", $new_path) ConsoleWrite($new_path & @CRLF) EndIf Func _help() ConsoleWrite(@CRLF & @CRLF & "Usage" & @CRLF & @CRLF & "Script to be used by WPKG to reorder/remove items out of the System PATH setting." & @CRLF & @CRLF & _ "Three arguments are required. The first argument is either 'remove', 'end' or 'begin'. The second argument is the string, full or partical, of " & _ "the item you want to remove, move to the end of the 'PATH' string or move to the beginning of the path string. Any parts of the existing 'PATH', " & _ "semi-colon seperated, matching the second argument will be deleted/moved. The third is either 'env' or 'reg'. 'env' = read in and manipulate " & _ "the 'PATH' environment variable. 'reg' reads in the subkey 'PATH' registry entry at HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\" & _ "Environment." & @CRLF & @CRLF & "This script returns the new path to the cmd line and sets the registry subkey. The 'PATH' is read in at next login." & _ @CRLF & @CRLF & "E.g." & @CRLF & @ScriptName & " remove miktex env = remove any parts of the environment variable 'PATH' with *miktex* in." & _ @CRLF & @CRLF & @ScriptName & " end miktex reg = move any parts of the 'PATH' registry subkey with *miktex* to the end of the " & _ " registry 'PATH' subkey" & @CRLF & @CRLF & @ScriptName & " begin miktex env = move any parts of the environment variable 'PATH' with *miktex* to the " & _ "beginning of the registry 'PATH' subkey" & @CRLF & @CRLF & _ "C. Mortimer April 2011" & @CRLF) EndFunc ;==>_help