我想檢查互聯網連接,當它失敗我想設置%internet%
未連接。如果它能工作到connected
。簡單的批量檢查互聯網連接和設置環境變量%互聯網%取決於結果
echo checking internet connection
Ping www.google.nl -n 1 -w 1000
cls
if errorlevel 1 (set internet=Not connected to internet)
if errorlevel 0 (set internet=Connected to internet)
我也試過這樣:
@echo off
cls
echo Checking connection
ping -n 1 www.google.com >nul
if errorlevel 1 (
cls
set "%internet%"=="Not connected to internet"
echo %internet%
pause>nul
exit
)
cls
set "%internet%"=="Connected to internet"
echo %internet%
pause>nul
pause
---------------編輯------------
這是更多的代碼。
@echo off
set versienummer=v3.1
title AutoMatic Program Install Stable %versienummer% by eric
color 0a
:CheckOS
IF "%PROCESSOR_ARCHITECTURE%"=="x86" (set bit=x86) else (set bit=x64)
set "windows="
VER | find " 5.1." > nul && set windows=XP
VER | find " 5.2." > nul && set windows=XP 64-Bit or Server 2003 or Server 2003 R2
VER | find " 6.0." > nul && set windows=Vista or server 2008
VER | find " 6.1." > nul && set windows=Win7 or server 2008 R2
VER | find " 6.2." > nul && set windows=Windows 8
VER | find " 6.3." > nul && set windows=Server 2012 R2 or Windows 8.1
if defined windows (
echo %windows%
) else (
echo unknown operating system
)
:ReturnToBaseLine
echo checking internet connection
Ping www.google.nl -n 1 -w 1000
cls
if errorlevel 1 (set internet=Not connected to internet)
if errorlevel 0 (set internet=Connected to internet)
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 internet
REM If we get here, we are not connected.
set internet=Not connected to internet
pause
REM Quit.
color 0a
cls
echo Made By The Amazing
echo.
echo ____ _ ________ ___
echo /__/___(_)___ /_ __//___ /_ \_______ ___ ___ _ ___ ____
echo/_// __//__/ ///_ \/ -_)////__/ -_) _ `/ ' \/ -_) __/
echo /___/_/ /_/\__/ /_/ /_//_/\__/ /____/_/ \__/\_,_/_/_/_/\__/_/
echo.
Echo %bit% processor architecture versie %versienummer%
echo %windows%
echo %internet%
echo.
----------------------------- edit 3 ------------ ------
DONE
與您的問題無關,但這可能會讓您的生活更輕鬆:'for/f「tokens = *」%%我在('wmic os獲得Caption ^,OSArchitecture/value^| find「=」' )do set %% i','echo%Caption%,%OSArchitecture%' – Stephan