Vbscript / General / Vbscript Logging Techniques
This script demonstrates script loggin techniques using text log files and the Windows event log.
Set objShell = WScript.CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject")
strLogLocation = "C:\"
strScript = Wscript.ScriptName strLogName = Left(strScript, Len(strScript)-4) & "Log.txt"
Set objLogFile = objFSO.OpenTextFile(strLogLocation & strLogName, 8, True)
strMsg = "Script Started" objLogFile.WriteLine(Now & vbTab & strMsg)
strMsg = "Script Ended" objLogFile.WriteLine(Now & vbTab & strMsg)
If Err.Number <> 0 Then objShell.LogEvent 2, "Error: " & strScript & vbCRLF & Err.Description Else objShell.LogEvent 0, "Success: " & strScript End If
objLog.Close
Set objLogFile = Nothing Set objFSO = Nothing Set objShell = Nothing
Please note that a disclaimer applies to any code on this page.
|