I have a script that is doing a few thing like running out to the web
and unzipping files is there any way to have the script create and send
all error to a log file.

Re: Error loging in VBscript by tlavedas

tlavedas
Tue Nov 29 12:13:44 CST 2005

See WSH documentation for LogEvents:
--------------------------------------------------------------------------
LogEvent Method
See Also
WshShell Object
Language
JScript

VBScript

Show All
Adds an event entry to a log file.

object.LogEvent(intType, strMessage [,strTarget])
Arguments
object
WshShell object.
intType
Integer value representing the event type.
strMessage
String value containing the log entry text.
strTarget
Optional. String value indicating the name of the computer system where
the event log is stored (the default is the local computer system).
Applies to Windows NT/2000 only.
Remarks
The LogEvent method returns a Boolean value (true if the event is
logged successfully, otherwise false). In Windows NT/2000, events are
logged in the Windows NT Event Log. In Windows 9x/Me, events are logged
in WSH.log (located in the Windows directory).
--------------------------------------------------------------------------

Tom Lavedas
============
http://my.fcc.net/~tglbatch (new URL - old content)

nebblkshts@yahoo.com wrote:
> I have a script that is doing a few thing like running out to the web
> and unzipping files is there any way to have the script create and send
> all error to a log file.


Re: Error loging in VBscript by DM

DM
Tue Nov 29 12:35:37 CST 2005

Yes, I have used the following method:

Create a network share that can be accessed via CIFS, or, if the script
is being run on your local workstation, youi can simply use a location
on one of your local drives.

Using the File System Object, the following code will enable you to
create an automated log file. The code I present to you assumes that
you are using a network share where 'ServerName' is the name of your
file share server, and 'LogFileShare' is the name of the share within
which you will store your log files, and FileName.txt is the name of
your text file.

First, you will need to instantiate the file system object as follows:

Set fsObject = CreateObject("Scripting.FileSystemObject")

Second, the below constants are fairly common and are used to declare
the input/output state of the log file when it is opened:

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Third, the path of the file is specified, along with the I/O state, and
whether the file is to be created if it is not already there:

Set objTxtLog =
fsObject.OpenTextFile("\\ServerName\LogFileShare\FileName.txt",
ForAppending, True)

Finally, the below code writes a line to the file if an error is
encountered. You can use the .writeline method, however, to create
just about any kind of text content that you would like for your log
file:

If Err <> 0
objTxtLog.Writeline Err & " You decide which text you want here"
End if

The above code is fairly generic, but you should be able to change it
as needed. You can read more about the file system object, with a
vbscript example of how this can be used, at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/script56/html/jsobjFileSystem.asp

The internet also contains a lot of information on the File Sytem
Object, as well as on the CreateTextFile and OpenTextFile methods, that
you might find useful in creating a log file of this type.


Re: Error loging in VBscript by nebblkshts

nebblkshts
Thu Dec 01 15:26:04 CST 2005

Thank you very much worked like a champ!