Hello, KiX community,
I've got a new problem at hand. Whilst writing my first UDF, I read the How to make a UDF by sealeopard .
I this 'How To' it was recommended that I wrote the code in most restrictive 'mode' available to KiX.
Also as a comment on an earlier snippet of code from me, there came as comment not to 'double quote' vars and macros.
So I tried to do this, underneath you'll find the code:
Code:
;Function CheckLog
;
;ACTION Log date, time, scriptname and logtext to registry
;
;AUTHOR P.C.E.P.M. Sanders (P_Style; philip@pcsanders.net)
;
;CONTRIBUTORS None
;
;VERSION 1.0
;
;DATE CREATED 2004/08/02
;
;DATE MODIFIED 2004/08/02
;
;KIXTART 4.22
;
;SYNTAX CheckLog ($LogTxt)
;
;PARAMETERS $LogTxt
; The text you want to have logged into the registry
;
;RETURNS 0
;
;REMARKS None
;
;DEPENDENCIES None
;
Function CheckLog($LogTxt)
Dim $Space, $XName, $LogKey
$LogKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Deployment\Logging'
$Space = Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32) + Chr(32)
$XName = SubStr ($Script, 1, Len($Script)-4) + Right ($Space, 15 - Len(SubStr ($Script, 1, Len($Script)-4)))
If @ERROR = 0
WriteValue ($LogKey,@DATE+' '+@TIME,$XName+''+$LogTxt,'REG_SZ')
Sleep 1
Else
Color r+/n
Box (4,24,8,45,'Full')
Color r+/n
At (5,26) 'ERROR ENCOUNTERED!'
At (7,26) 'CALL LINE OPERATOR'
WriteValue ($LogKey,@DATE+' '+@TIME,$XName+''+$LogTxt+' FAILED!!','REG_SZ')
Color w+/n
Do
Beep
Beep
Beep
Until KBHit()
EndIf
EndFunction
This is working well.
However I call scripts from a central script. This central script checks the registry wheter or not to install software. You'll find a snippet here:
Code:
:Platform
? ' Routines called from loadsetserver.....'
$KixScr = ReadValue ($ScrKey,'Platform.kix')
If @ERROR = 0 AND $KixScr = 'Installed'
GoTo NLSet
Else
Call 'Z:\Scripts\Platform\Platform.kix'
EndIf
:NLSet
$KixScr = ReadValue ($ScrKey,'NLSet.kix')
If @ERROR = 0 AND $KixScr = 'Installed'
GoTo NLApps
Else
Call 'Z:\Scripts\NLSet\NLSet.kix'
EndIf
Before I execute this script I declare global and local vars, call udf's and udl's, set up the console like this:
Code:
; ===== OPTIONS / VARIABLES / USER DEFINED FUNCTION / USER DEFINED LIBRARIES =========
; ----- Set Options ------------------------------------------------------------------
SetOption ('ASCII','ON')
SetOption ('HideCursor','ON')
SetOption ('WrapAtEOL','ON')
SetOption ('Explicit','On')
SetOption ('NoVarsInStrings','On')
SetOption ('CaseSensitivity','On')
; ----- Call Required UDF's and UDL's ------------------------------------------------
Call 'Z:\SCRIPTS\UDF\CheckLog.UDF'
; ----- Declare Global Variables -----------------------------------------------------
Global $DepKey, $OldKey, $ScrKey, $CurVer, $WinLog, $PolKey, $DefUsr, $Script, $Server
SetConsole ('Maximize')
$DepKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Deployment'
$OldKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Deployment\OldMachine'
$ScrKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Deployment\Scripts'
$CurVer = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion'
$WinLog = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon'
$RunKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run'
$PolKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows'
$DefUsr = 'HKEY_USERS\EYInst'
$Script = @SCRIPTNAME
$Server = '\\LoadSrv'
; ----- Declare Local Variables ------------------------------------------------------
Dim $KixScr, $LoadSetRun
; ----- Set Up Console ---------------------------------------------------------------
SetConsole ('Maximize')
Color w+/n
; ----- Setting registry keys for installation ---------------------------------------
WriteValue ($ScrKey,@SCRIPTNAME,"Busy","REG_SZ")
; ----- Which script is called -------------------------------------------------------
CLS
Color y+/n
? ' '
? ' === ===> Running @SCRIPTNAME <=== ==='
Color w+/n
This last section I intend to make this a sort of 'default' for every script which is called. So every script will start with these lines.
Depending on the script local vars will differ.
Is it wise to do so? Is there a better way to make this happen?
I hope you can come up with some answers and maybe raise new questions.
t.i.a.