how to log VBScript Runtime errors

March 31, 2010 at 09:56:06
Specs: Windows server 2003 sp2
how can i log the windows script host error messages in my code when i detects a error

See More: how to log VBScript Runtime errors

Report •


#1
March 31, 2010 at 10:20:24
What do you mean? The script should just bomb with an error message if there's a runtime problem.

Report •

#2
March 31, 2010 at 10:25:11
Correct but i want to log what that error message says.

Report •

#3
March 31, 2010 at 10:48:14
That might be difficult to answer without knowing how you're invoking the scripts, but I assume you want something like this:
cscript [your script] 2>>error.log


Report •

Related Solutions

#4
March 31, 2010 at 10:53:27
Const ForAppending = 8

strComputer = "."
'Sets the Destination diretory of where the files are to be copied
sDestinationFolder = "W:\blah\"
'Sets the path of where the log file is to be created
strLogfile = "D:\blah\AutoCopy.log"

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open log file
If objFSO.FileExists(strLogFile) Then
Set strLog = objFSO.OpenTextFile(strLogfile, ForAppending)
Else
Set strLog = objFSO.CreateTextFile(strLogfile)
End If

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\cimv2")

'Query for new files every 60 seconds
Set colMonitoredEvents = objWMIService.ExecNotificationQuery _
("SELECT * FROM __InstanceCreationEvent WITHIN 60 WHERE " _
& "Targetinstance ISA 'CIM_DirectoryContainsFile' and " _
& "TargetInstance.GroupComponent= " _
& "'Win32_Directory.Name=""d:\\\\blah\\\\blah\\\\working""'")

'Loop through all the new files
Do
Set objLatestEvent = colMonitoredEvents.NextEvent
strFilenameArray = split (objLatestEvent.TargetInstance.PartComponent, "=")
strFilename = replace(strFilenameArray(1), "\\", "\")
strFilename = replace(strFilename, """", "")

'Copy the new file to the destination folder
objFSO.CopyFile strFilename, sDestinationFolder
strLog.Writeline Now() & ", Copied file " & strFilename & " to " & sDestinationFolder
Loop

Wscript.Quit


Report •

#5
March 31, 2010 at 10:59:32
That's the script itself, not how you're invoking (read: running) it.

Report •

#6
March 31, 2010 at 11:01:24
from a batch using this command
call "OSA Deposit Confirms".vbs

Report •

#7
March 31, 2010 at 11:05:44
cscript "OSA Deposit Confirms.vbs" 2>> errorLog.txt


Report •

#8
March 31, 2010 at 12:25:04
That is exactly what i wanted

Report •


Ask Question