Link to home
Start Free TrialLog in
Avatar of Cuteadder
CuteadderFlag for Australia

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("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
Else
fso.CopyFile "C:\batch\*.eml", "q:\", True
End If
Avatar of Surone1
Surone1
Flag of Suriname image

i dont see the scripting.filesystemobject being created, but since it's only one file to copy you should probably use shell or shellexecute
Avatar of Cuteadder

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 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("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
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
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("WScript.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & strTarget) 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
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.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & "www.sr.net") 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
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
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.Shell")
Set WshExec = WshShell.Exec("ping -n 3 -w 2000 " & "www.yahoo.co.uk") 'send 3 echo requests, waiting 2secs each
strPingResults = LCase(WshExec.StdOut.ReadAll)
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
Avatar of Surone1
Surone1
Flag of Suriname 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
fantastic, thank you very much!
my pleasure