Outputting Standard Out information from a VBS Script

Hi guys,

Im pretty new to VBScript, and would love your help.

What I have is the following:

========================================= BOF
bolIsRightSubnet = False
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
    ("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")

For Each IPConfig in IPConfigSet
    If Not IsNull(IPConfig.IPAddress) Then
        For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
            If Left(IPConfig.IPAddress(i), 9) = "10.60.10." Or Left(IPConfig.IPAddress(i), 9) = "10.60.11." Then
    bolIsRightSubnet = True
   End If
        Next
    End If
' Hi there
Next
If bolIsRightSubnet = True Then
    strComputerToPing = "tiger"
    bolRunCopyJob = False
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
        ExecQuery("select * from Win32_PingStatus where address = '"_
            & strComputerToPing & "'")
    For Each objStatus in objPing
        If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
            WScript.Echo("machine " & strComputerToPing & " is not reachable")
    Else
      bolRunCopyJob = True
        End If
    Next
End If
If bolRunCopyJob = True Then
'      set WshShell = WScript.CreateObject("WScript.Shell")
'      WshShell.run "d:\a.bat"
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.CopyFile "d:\y.txt" , "h:\2\", OverwriteExisting
Else      set WshShell = WScript.CreateObject("WScript.Shell")
      WshShell.run "notepad", 3, False
End If
========================================= BOF

What it does:

It first enumerates the IP Address of the machine
If the IP address is on a particular subnet eg.10.60.10 or 10.60.11.x, it fires the backup job.
If not on this subnet, it doesnt copy.

What Im having trouble with is this.

Id like to write a log file of the vbscript activity.
I know how to do this in a batch file, for example:

net use s: \\server\share >> c:\nab.log 2>&1

Which outputs to the nab.log file the following:

"The command completed successfully"

In my vbscript:

Id like to be able to do the following, logging everything that is going on.

For example, in the log file, Id like:

**************************************
Wed 27/10/2004
6:45 pm

The IP address of this system is "x.x.x.x"
Executing backup job
Copying file d:\y to H:\2
Backup completed at 6:47pm
Or

***************************************
Wed 27/10/2004

The IP address of this system is "x.x.x.x"
This system is not on the required subnet
Abort backup job

Any help on this would be greatly appreciated.


Simon


LVL 1
Simon336697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David LeeCommented:
Hello, Simon.

This isn't exactly what you asked for, but it accomplishes your goal.  The simple solution is to create the log file in the script using the following code.

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTS = objFSO.CreateTextFile("C:\Log.Txt")  '<-- Change the path and filename as needed

You can then write to the log file wherever you choose using this code:

    objTS.WriteLine "Write whatever you want, including the value(s) of variables"

At the end of your script you'll need to close the file like this:

    objTS.Close

And of course to avoid memory leaks all objects should be disposed of properly:

    Set objTS = Nothing
    Set objFSO = Nothing
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Simon336697Author Commented:
Thanks BlueDevil,

Really appreciate it!!!

Simon
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows 2000

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.