Simon336697
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_NetworkAdapterConfig uration where IPEnabled=TRUE")
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress) Then
For i=LBound(IPConfig.IPAddres s) 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:{imper sonationLe vel=impers onate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& strComputerToPing & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCod e) 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("WScr ipt.Shell" )
' WshShell.run "d:\a.bat"
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
objFSO.CopyFile "d:\y.txt" , "h:\2\", OverwriteExisting
Else set WshShell = WScript.CreateObject("WScr ipt.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
Im pretty new to VBScript, and would love your help.
What I have is the following:
==========================
bolIsRightSubnet = False
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set IPConfigSet = objWMIService.ExecQuery _
("Select IPAddress from Win32_NetworkAdapterConfig
For Each IPConfig in IPConfigSet
If Not IsNull(IPConfig.IPAddress)
For i=LBound(IPConfig.IPAddres
If Left(IPConfig.IPAddress(i)
bolIsRightSubnet = True
End If
Next
End If
' Hi there
Next
If bolIsRightSubnet = True Then
strComputerToPing = "tiger"
bolRunCopyJob = False
Set objPing = GetObject("winmgmts:{imper
ExecQuery("select * from Win32_PingStatus where address = '"_
& strComputerToPing & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCod
WScript.Echo("machine " & strComputerToPing & " is not reachable")
Else
bolRunCopyJob = True
End If
Next
End If
If bolRunCopyJob = True Then
' set WshShell = WScript.CreateObject("WScr
' WshShell.run "d:\a.bat"
Const OverwriteExisting = True
Set objFSO = CreateObject("Scripting.Fi
objFSO.CopyFile "d:\y.txt" , "h:\2\", OverwriteExisting
Else set WshShell = WScript.CreateObject("WScr
WshShell.run "notepad", 3, False
End If
==========================
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Really appreciate it!!!
Simon