|
I have a (lengthy) script which is going to be part of an even larger one. Its purpose is to download and install patches as they become available, when the user starts the system. They are installed by running pkunzip from within a KiX SHELL command.
It all works fine except that if patches are installed (i.e. the SHELL command is executed), the script will not exit.
Here's the script (Note that the MessageBox call immediately before the EndFunction is executed, but the following quit is not. The script exits normally (even without the quit) if the SHELL command is not executed):
;;;;;;;;;;;;;;;;;; Script ;;;;;;;;;;;;;;;;;;;;;
; Globals
$patchDirPath = "\\cimisweb\cimis\common\deployment\patches\8203\" $usysDir = "c:\usys82\" $patchLogFileName = "patchlog.txt"
InstallPatches()
Function InstallPatches Dim $WinVer Dim $patchLogFile Dim $empty $InstallPatches = 0 ; Is Uniface 8.2 installed? if not exist ( $usysDir ) MessageBox( "Error: Missing Usys82 Directory", "Patches", 16 ) quit -1 endif ; Does the patch directory path exist? if not exist ( $patchDirPath ) MessageBox( "Error: Missing Patch Directory Path", "Patches", 16 ) quit -1 endif
; Store the Windows Version
$WinVer = @ProductType
; Find the patch directory (don't need 95 or NT) $patchDir = TestAndSetPatchDir( $WinVer, "98" ) if $patchDir = "" $patchDir = TestAndSetPatchDir( $WinVer, "2000" ) if $patchDir = "" $patchDir = TestAndSetPatchDir( $WinVer, "XP" ) if $patchDir = "" MessageBox("Error: Unsupported Operating System", "CIMIS 2000 - Patches", 16) quit -1 endif endif endif
;MessageBox( "Windows Version is: " + $WinVer, "Patches", 64) ;MessageBox( "Patch directory is: " + $patchDir, "Patches", 64) if not exist ( $patchDir ) MessageBox( "Error: Patch Directory does not exist", "Patches", 16 ) quit -1 endif $patchLogFile = $usysDir + $patchLogFileName ;MessageBox( "Patch Log File is: " + $patchLogFile, "Patches", 64 ) $empty = 1 $patch = Dir( $patchDir ) While $patch = "." or $patch = ".." $patch = Dir() Loop
;$count = 0 While $patch <> "" and @ERROR = 0 ;$count = $count + 1 ;MessageBox("Loop iteration no: " + $count, "Patches", 64)
if $empty = 1 $empty = 0 endif ; Create the patches log file if it doesn't exist, and open it for reading if open( 4, $patchLogFile, 3 ) = 0
; read a line from the patch log file $lineFromPatchLogFile = ReadLine( 4 ) while $patch <> $lineFromPatchLogFile and @ERROR = 0 $lineFromPatchLogFile = ReadLine( 4 ) loop $saveError = @ERROR endif close ( 4 ) ;MessageBox("saveError is: " + $saveError + @CRLF + "patch is: " + $patch + @CRLF + "lineFromPatchLogFile is: " + $linefrompatchfile, "Patches", 64) if $saveError = -1 or $patch <> $lineFromPatchLogfile MessageBox( "Installing patch: " + $patch, "CIMIS2000 - Patches", 64 ) ; do pkunzip stuff $cmd = "m:\common\deployment\pkunzip.exe -d " + $patchDir + $patch + " " + $usysDir + " -o" shell $cmd ; open patch log file for writing (error if doesn't exist) if open( 4, $patchLogFile, 4 ) = 0 ; append patch file name to patch log file (+CRLF) WriteLine( 4, $patch + @CRLF ) ; close patch log file close( 4 ) else MessageBox( "Error: Couldn't open patch log file!", "CIMIS 2000 - Patches", 16 ) quit -1 endif endif $patch = Dir() ; retrieve next file ;MessageBox("Error code is: " + @ERROR + @CRLF + "Next patch is: " + $patch, "Patches", 64) Loop MessageBox("Left loop", "Patches", 64) if $empty = 1 ; patch directory is empty MessageBox("Patch file empty. Nothing to do", "Patches", 64) ; delete the patch log file if exist ( $patchLogFile ) del $patchLogFile endif endif MessageBox("Leaving Function", "Patches", 64) quit 0 EndFunction
Function TestAndSetPatchDir( $windowsVersion, $pattern ) $TestAndSetPatchDir = "" $startIndex = INSTR ($windowsVersion, $pattern ) if $startIndex > 0 $TestAndSetPatchDir = $patchDirPath + "W" + $pattern + "\" Endif EndFunction
|