I am newbie with scripting and programming. I have a VB script that run a
ping.exe command to see if the other server is up. The ping.exe VB scripts
works fine but I would like to include a statement where if the ping command
return request time out (the other server is down) instead of a reply
(meaning the other server is up) then it will call the batch file call
service.bat. here is my code for the ping VB script and the batch file. How
could I do this?

Ping VB Script:

Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec("ping 10.0.0.1 -t")
Set objStdOut = objWshScriptExec.StdOut

Do Until objStdOut.AtEndOfStream
strLine = objStdOut.ReadLine
If Len(strLine) > 2 Then
WScript.Echo Now & " -- " & strLine
Else
Wscript.Echo strLine
End If
Loop


Batch File to start Windows Service
sc start WZCSVC

Re: call a batch file within VB script??? by Ayush

Ayush
Fri Jan 26 16:06:30 CST 2007

Replied to [johnisccp]s message :
> I am newbie with scripting and programming. I have a VB script that run a
> ping.exe command to see if the other server is up. The ping.exe VB scripts
> works fine but I would like to include a statement where if the ping command
> return request time out (the other server is down) instead of a reply
> (meaning the other server is up) then it will call the batch file call
> service.bat. here is my code for the ping VB script and the batch file. How
> could I do this?


You can call the batch file by using the Run method of WshShell :

set wsh = CreateObject("WScript.Shell")
wsh.Run "C:\BatFiles\BatFile.bat"

you can also run "sc start WZCSVC" :
wsh.Run "sc.exe start WZCSVC"

--
â?? Ayush
-------------
Search - www.Google.com | Wikipedia - http://en.wikipedia.org
Snip your long urls - http://snipurl.com/
-------------

RE: call a batch file within VB script??? by Yann

Yann
Fri Jan 26 19:44:00 CST 2007

Your script is almost done, just add:

If Instr(strLine,"Request Time Out") <> 0 Then
objShell.Exec("%comspec% /c " & myBatchProgram)
Else wscript.echo "Everything is fine!!"
EndIf

Is it what you need?

Regards,
Yann

"johnisccp" wrote:

> I am newbie with scripting and programming. I have a VB script that run a
> ping.exe command to see if the other server is up. The ping.exe VB scripts
> works fine but I would like to include a statement where if the ping command
> return request time out (the other server is down) instead of a reply
> (meaning the other server is up) then it will call the batch file call
> service.bat. here is my code for the ping VB script and the batch file. How
> could I do this?
>
> Ping VB Script:
>
> Set objShell = CreateObject("WScript.Shell")
> Set objWshScriptExec = objShell.Exec("ping 10.0.0.1 -t")
> Set objStdOut = objWshScriptExec.StdOut
>
> Do Until objStdOut.AtEndOfStream
> strLine = objStdOut.ReadLine
> If Len(strLine) > 2 Then
> WScript.Echo Now & " -- " & strLine
> Else
> Wscript.Echo strLine
> End If
> Loop
>
>
> Batch File to start Windows Service
> sc start WZCSVC
>