Cuteadder
asked on
VB script to copy file is no response from PING
I want a VB script to copy a file if there is no response from an ip address, all I have so far is:
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.78.33.253" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA ll)
If InStr(strPingResults, "reply from") Then
Else
fso.CopyFile "C:\batch\*.eml", "q:\", True
End If
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.78.33.253" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScr
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA
If InStr(strPingResults, "reply from") Then
Else
fso.CopyFile "C:\batch\*.eml", "q:\", True
End If
i dont see the scripting.filesystemobject being created, but since it's only one file to copy you should probably use shell or shellexecute
ASKER
ok, sounds good, but I'm not sure about the usage on shell or shellexecute
I'm near enough a beginner on VB scripts
I'm near enough a beginner on VB scripts
ASKER
I just need to move a file or run a batch file if there is no response on ping
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- -
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.78.33.253" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA ll)
If InStr(strPingResults, "reply from") Then
Else
ObjShell.Exec d:\hello.bat, 0, True
End If
--------------------------
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.78.33.253" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScr
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA
If InStr(strPingResults, "reply from") Then
Else
ObjShell.Exec d:\hello.bat, 0, True
End If
ObjShell.Exec "copy d:\hello.bat d:\destdir", 0, True
ASKER
Its not coming up with an error, it is coming up with a box that I presume is pinging something, but the end result isn't happening - the file is not been copied
-------------------------- ---------- ---------- ---------- ---------- --
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.78.33.253" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA ll)
If InStr(strPingResults, "reply from") Then
Else
ObjShell.Exec "copy d:\hello.bat d:\destdir", 0, True
End If
--------------------------
On Error Resume Next
Dim strTarget, strPingResults
strTarget = "10.78.33.253" 'IP address or hostname
Set WshShell = WScript.CreateObject("WScr
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA
If InStr(strPingResults, "reply from") Then
Else
ObjShell.Exec "copy d:\hello.bat d:\destdir", 0, True
End If
Private Sub Form_Load()
Set WshShell = CreateObject("WScript.Shel l")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & "www.sr.net") 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA ll)
If InStr(strPingResults, "reply from") Then
Else
WshShell.Exec "copy C:\batch\*.eml q:\"
End If
End Sub
Set WshShell = CreateObject("WScript.Shel
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & "www.sr.net") 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA
If InStr(strPingResults, "reply from") Then
Else
WshShell.Exec "copy C:\batch\*.eml q:\"
End If
End Sub
oops i left my testing url inthere
this gives me a file not found error so it is attempting to copy something
this gives me a file not found error so it is attempting to copy something
ASKER
Tried the code below, no result and no error message. tried on both a Win7 machine and a 2008 server
-------------------------- ---------- ---------- ---------- ---------- ---------- -----
Private Sub Form_Load()
Set WshShell = CreateObject("WScript.Shel l")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & "www.yahoo.co.uk") 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA ll)
If InStr(strPingResults, "reply from") Then
WshShell.Exec "copy c:\new.txt c:\new"
Else
WshShell.Exec "copy c:\new.txt c:\new"
End If
End Sub
--------------------------
Private Sub Form_Load()
Set WshShell = CreateObject("WScript.Shel
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & "www.yahoo.co.uk") 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadA
If InStr(strPingResults, "reply from") Then
WshShell.Exec "copy c:\new.txt c:\new"
Else
WshShell.Exec "copy c:\new.txt c:\new"
End If
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
fantastic, thank you very much!
my pleasure