;--[   Function: WriteLog()    ]----------(last revised: 4/6/2002)-
;
;- Author:
;
;    Howard A. Bullock
;
;- Action:
;
;    Permanently opens the file coded in the UDF as file handle "1" and writes time stamped text to file handle "1" throughout the execution of your script.
;
;- Syntax:
;
;    WriteLog ($text)
;
;- Parameters:
;
;    $text  (Required / String)
;       Line of text to be written to the file.
;
;- Remarks:
;
;    This UDF is intended to be the main logging mechanism of the script. It opens file handle "1" the first time it is executed but does not close it. It then  writes text to file handle "1" every time it is invoked. Therefore this function should be called at the very beginning of your script so that you are sure to get file handle "1".
;    This UDF was designed to be a quick & simple way to have a log file generated. In our environment, a sub-script can be written and maintained by local LAN Admins. This is the common logging UDF that can be easily employed by them to continue logging data to a common file.
;    See Writelog2() if you need to specify multiple log files or for logging requirements that do not require the timestamp.
;
;- Returns:
;
;    Nothing
;
;- Dependencies:
;
;    None
;
;- Example:
;
;    WriteLog("")
;    WriteLog("Starting Kixtart script")
;
FUNCTION WriteLog ($text)
  DIM $rc, $text, $logfile, $filehandle

  $filehandle=1
  $logfile="%temp%\logon.log"
  $rc=WriteLine ($filehandle, "@Date @Time - $Text" + Chr(13) + Chr(10))
  IF ($rc < 0)
    $rc=Close($filehandle)
    $rc=Open($filehandle, "$LogFile", 5)
    SELECT
    CASE ($rc = -1)
      $rc=MessageBox("Invalid file name ($LogFile) specified for log file.","Logon Script Error",48)
    CASE ($rc = 0)
      writelog ($text)
    CASE ($rc => 0)
      $rc=MessageBox("Error($RC) while attempting to open log file ($LogFile).","Logon Script Error",48)
    ENDSELECT
  ENDIF
ENDFUNCTION ; - WriteLog -