Hi guys,

Id like to be able to generate a log file that pumps out all the steps that
a vbscript does.
Similar to using a batch file >> log.txt
And all errors.

Can someone steer me in the right direction?

Thank you.

Simon

Re: Creating a log file of a vbscript's activity by Richard

Richard
Tue Nov 30 22:50:12 CST 2004

Michelle wrote:

> Id like to be able to generate a log file that pumps out all the steps
that
> a vbscript does.
> Similar to using a batch file >> log.txt
> And all errors.
>
> Can someone steer me in the right direction?

Hi,

The simplest approach would be run the script at a command prompt and echo
info to the screen. Then, you can redirect the output to a text file. For
example, the VBScript could be similar to:

=============
' Do something.
Wscript.Echo "Step 1 complete"

' Do something else.
Wscript.Echo "Step 2 complete"
=============

If the VBScript file is called Project.vbs, run this at a command prompt
with the following. The log is in the file Project.log

cscript //nologo Project.vbs > Project.log

A more advanced method would be to use the FileSystemObject to write lines
to a text file. I have a sample logon VBScript that logs information this
way linked here:

http://www.rlmueller.net/Logon5.htm

The procedure in brief is:

=============
' Bind to FileSystemObject.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open a log file for write access.
' This creates the file if it does not exist.
Set objLogFile = objFSO.OpenTextFile("c:\MyFolder\MyFile.Log", 8, True, 0)

' Write to the log file.
objLogFile.WriteLine "Step 1 complete at " & Now

' Write another line to the file.
objLogFile.WriteLine "Step 2 complete at " & Now

' Be sure to close the file.
objLogFile.Close
=============

Errors will not get redirected to a file with either method. However, you
could trap anticipated errors, using "On Error Resume Next", "On Error GoTo
0", and "If Err.Number <> 0 Then". For example, extending the second snippet
above:

=============
objLogFile.WriteLine "Starting Step 3"

' Trap possible error.
On Error Resume Next
Set objUser = GetObject("LDAP://cn=JUser,ou=Sales,dc=MyDomain,dc=com")
If Err.Number <> 0 Then
' Attempt to bind objUser failed. Restore normal error handling.
On Error GoTo 0
objLogFile.WriteLine "Error - failed to bind objUser"
Else
' Bind succeeded. Restore normal error handling.
On Error GoTo 0
objLogFile.WriteLine "Step 3 complete"
End If
=============

You could also use Wscript.Echo above. I try to turn off normal error
handling only for the statements I anticipate could raise an error. Look up
documentation on the Err object. Err.Number will be 0 if there is no error
condition.

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--



Re: Creating a log file of a vbscript's activity by Thorsten

Thorsten
Wed Dec 01 04:12:53 CST 2004

Why you don't use the subprocedure I've sent you via email?

"Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
news:%1ard.54223$K7.29435@news-server.bigpond.net.au...
> Hi guys,
>
> Id like to be able to generate a log file that pumps out all the steps
> that a vbscript does.
> Similar to using a batch file >> log.txt
> And all errors.
>
> Can someone steer me in the right direction?
>
> Thank you.
>
> Simon
>



Re: Creating a log file of a vbscript's activity by Michelle

Michelle
Wed Dec 01 20:10:32 CST 2004

Hi Thorsten,

My huge apologies.

I didnt think you had sent it, but my Zone Alarm had quarrantined your
email.

Thank you so much mate.....I so much appreciate the time you have put into
this.

Simon


"Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
news:eRP2R541EHA.3616@TK2MSFTNGP11.phx.gbl...
> Why you don't use the subprocedure I've sent you via email?
>
> "Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
> news:%1ard.54223$K7.29435@news-server.bigpond.net.au...
>> Hi guys,
>>
>> Id like to be able to generate a log file that pumps out all the steps
>> that a vbscript does.
>> Similar to using a batch file >> log.txt
>> And all errors.
>>
>> Can someone steer me in the right direction?
>>
>> Thank you.
>>
>> Simon
>>
>
>



Re: Creating a log file of a vbscript's activity by Thorsten

Thorsten
Thu Dec 02 02:30:31 CST 2004

*LOL*
Seems that I'll be now classified as a bad boy in Australia...
Okay, if you still want to get the script, just tell me what format will be
allowed to pass your Anti-Bad-Boy-Software.

Thorsten

"Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
news:sQurd.55608$K7.16470@news-server.bigpond.net.au...
> Hi Thorsten,
>
> My huge apologies.
>
> I didnt think you had sent it, but my Zone Alarm had quarrantined your
> email.
>
> Thank you so much mate.....I so much appreciate the time you have put into
> this.
>
> Simon
>
>
> "Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
> news:eRP2R541EHA.3616@TK2MSFTNGP11.phx.gbl...
>> Why you don't use the subprocedure I've sent you via email?
>>
>> "Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
>> news:%1ard.54223$K7.29435@news-server.bigpond.net.au...
>>> Hi guys,
>>>
>>> Id like to be able to generate a log file that pumps out all the steps
>>> that a vbscript does.
>>> Similar to using a batch file >> log.txt
>>> And all errors.
>>>
>>> Can someone steer me in the right direction?
>>>
>>> Thank you.
>>>
>>> Simon
>>>
>>
>>
>
>



Re: Creating a log file of a vbscript's activity by Michelle

Michelle
Fri Dec 03 17:02:18 CST 2004

Thanks Thorsten,

I have it out of quarrantine now.

Really appreciate it.

Simon


"Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
news:OLxpvkE2EHA.936@TK2MSFTNGP12.phx.gbl...
> *LOL*
> Seems that I'll be now classified as a bad boy in Australia...
> Okay, if you still want to get the script, just tell me what format will
> be allowed to pass your Anti-Bad-Boy-Software.
>
> Thorsten
>
> "Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
> news:sQurd.55608$K7.16470@news-server.bigpond.net.au...
>> Hi Thorsten,
>>
>> My huge apologies.
>>
>> I didnt think you had sent it, but my Zone Alarm had quarrantined your
>> email.
>>
>> Thank you so much mate.....I so much appreciate the time you have put
>> into this.
>>
>> Simon
>>
>>
>> "Thorsten Helfer" <thorsten.helfer@it-helfer.de> wrote in message
>> news:eRP2R541EHA.3616@TK2MSFTNGP11.phx.gbl...
>>> Why you don't use the subprocedure I've sent you via email?
>>>
>>> "Michelle" <mhillard@bigpond.net.au> schrieb im Newsbeitrag
>>> news:%1ard.54223$K7.29435@news-server.bigpond.net.au...
>>>> Hi guys,
>>>>
>>>> Id like to be able to generate a log file that pumps out all the steps
>>>> that a vbscript does.
>>>> Similar to using a batch file >> log.txt
>>>> And all errors.
>>>>
>>>> Can someone steer me in the right direction?
>>>>
>>>> Thank you.
>>>>
>>>> Simon
>>>>
>>>
>>>
>>
>>
>
>