Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

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


ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Simon336697

ASKER

Thanks BlueDevil,

Really appreciate it!!!

Simon