I am trying to write a script that will discovery hosts on a subnet but I am running into one problem. For some reason the line in red doesn't output anything to the logfile. But if I put the actual run statment into a command prompt it outputs fine.
Anyone have some ideas on why not?
Anyone have some ideas on why not?
Code:
Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
vCleanedLog = "C:\SortedIP.Log"
vSubnet = "10.30.3."
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\IP.Log"
'Ping all the IPs in our subnet and write results to text file
For x = 1 To 25
[COLOR=red]oShell.Run "%comspec% /c ping -a " & vSubnet & x & " >> " & sTempFile, 0, True[/color]
WScript.Sleep 5000
Next
'now read the text file and strip out the junk
vReport = ""
MyList= oFSO.OpenTextFile(sTempFile, ForReading).ReadAll
myArray=Split(MyList,vbCrLf, -1, vbtextcompare)
For Each Val In myArray
If Left(Val,7)= "Pinging" Then
Report = Report & Val & vbCrLF
End If
Next
Set ts = oFSO.CreateTextFile (vCleanedLog, ForWriting, True)
ts.Write vReport
MsgBox "Done"