I want to check internet connection, when it fails I want to set %internet% to not connected. And if it works to connected.
echo ch
This worked for me. The idea is it checks each line of the PING result for the line starting with "Reply" (which indicates success) and if it finds it on a single line then it sets the %Connected% variable to true.
@ECHO OFF
SET Connected=false
FOR /F "usebackq tokens=1" %%A IN (`PING google.com`) DO (
REM Check the current line for the indication of a successful connection.
IF /I "%%A"=="Reply" SET Connected=true
)
REM Check if a success was found.
IF "%Connected%"=="true" (
SET Internet=Connected to the internet.
) ELSE (
SET Internet=Not connected to the internet.
)