I want to present a pop up message based on the outcome of a ping comannd, how ever regardless of whether the ping fails or passes the ping was successful message is executed:
start "Checking your PC is on the network- ...."%host% ping localhost |find "TTL=">nul && (msg "%username%": Ping to Local Host Failed) || (msg "%username%" Ping to Local host Succesful)
start "Checking Gateway for computer - ..."%host% ping 10.89.24.1 -t -a -n 5 |find "TTL=">nul && (msg "%username%": Ping to Gatewway Failed) || (msg "%username%" Ping to Gateway Succesful)
start "Checking Apex Server for computer -...."%host% ping 193.120.187.44 -t -a -n 5 |find "TTL=">nul && (msg "%username%": Ping to Apex Server Failed) || (msg "%username%" Ping to Apex Server Succesful)
start "Checking Intranet Connection- ...."%host% ping 10.89.208.9 -t -a -n 5 |find "TTL=">nul && (msg "%username%": Ping to Intranet Failed) || (msg "%username%" Ping to Intranet Successful)
EDIT Have updated code- however the if errorlevel 0
condition executes regardless of whether the ping is successful or not, I think this may be because the ping command executes successfully so the errorLevel = 0, regardless of the outcome i.e. TTL
@echo off
set host=%COMPUTERNAME%
rem color 0b
timeout 4
start "STEP 1 Checking your PC is on the network- ...."%host% ping localhost -n 4 >NUL
echo %Errorlevel%
if errorLevel 0 (
msg * "PC is connected to the network"
) else (
msg * "PC is not connected to the network, check PC is plugged into network point"
)
timeout 4
start "STEP 2 Checking Gateway for computer - ..."%host% ping 10.89.24.1 -n 4 >NUL
echo %Errorlevel%
if errorLevel 0 (
msg * "PC is connected to the Router/Gateway"
) else (
msg * "PC is not connected to the Router/Gateway"
)
timeout 4
start "STEP 3Checking Apex Server for computer -...."%host% ping 193.120.187.44 -n 4 >NUL
echo %Errorlevel%
if errorLevel 0 (msg * "PC is connected to Apex, chck the APex application and/or raise an iASSIT"
) else (
msg * "PC is not connected to the Apex, network down"
)
timeout 4
start "STEP 4 Checking Intranet Connection- ...."%host% ping 10.89.208.9 -n 4 >NUL
echo %Errorlevel%
if errorLevel 0 (msg * "PC is connected to the Intranet"
) else (
msg * "PC is not connected to the Intranet")
timeout 4
start "STEP 5 Checking Internet Connection- ...."%host% ping www.rotunda.ie -n 4 >NUL
echo %Errorlevel%
if errorLevel 0 (msg * "PC is connected to the Internet"
) else (
msg * "PC is not connected to the Internet")