Hello,
I have the following line in a vb script:
where sText is a line in a text file that contains ip addresses, one per line, and sLog is the text file in which to write the results.
The code works only for the a single ip address; then it returns "The process cannot access the file because it is being used by another process." This error must pertain to the
part of the line, because when I leave it off, all of the ping results are written to their respective command windows.
How can I automatically append each ping result to the end of the sLog file?
Here's the entire script:
Thanks in advance!
I have the following line in a vb script:
Code:
wshShell.run("%comspec% /k ping -a -n 1 " & sText & " >> " & sLog)
where sText is a line in a text file that contains ip addresses, one per line, and sLog is the text file in which to write the results.
The code works only for the a single ip address; then it returns "The process cannot access the file because it is being used by another process." This error must pertain to the
Code:
& " >> " & sLog)
part of the line, because when I leave it off, all of the ping results are written to their respective command windows.
How can I automatically append each ping result to the end of the sLog file?
Here's the entire script:
Code:
Option Explicit
On Error Resume Next
Dim wshShell
Dim strHost
Dim strCommand
Dim strLine
Dim oFSO, sFile, oFile, sText, sLog
Set wshShell = wscript.createObject("wscript.shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sFile = "indexIPs.txt"
sLog = "Log.txt"
If oFSO.FileExists(sFile) Then
Set oFile = oFSO.OpenTextFile(sFile, 1)
Do While Not oFile.AtEndOfStream
sText = oFile.ReadLine
If Trim(sText) <> "" Then
strCommand = sText
wshShell.run("%comspec% /k ping -a -n 1 " & sText [red]& " >> " & sLog[/red])
[green]' wshShell.run("%comspec% /k ping -a -n 1 " & sText) 'this works as explained above[/green]
End If
Loop
oFile.Close
Else
WScript.Echo "File '" & sFile & "' was not found."
End If
If Err <> 0 Then
wscript.echo "Error Type = " & Err.Description
End If
WScript.Quit
Thanks in advance!