title: Simple batch for checking internet connectivity and setting environment variable %internet% depending on result
body: <p>I want to check internet connection, when it fails I want to set <code>%internet%</code> to not connected. And if it works to <code>connected</code>.</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>I also tried this:</p>
  
  <pre><code>@echo off
  cls
  echo Checking connection
  ping -n 1 www.google.com &gt;nul
  if errorlevel 1 (
    cls
    set "%internet%"=="Not connected to internet"
    echo %internet%
    pause&gt;nul
    exit
  )
  
  cls
  set "%internet%"=="Connected to internet"
  echo %internet%
  pause&gt;nul
  pause
  </code></pre>
  
  <p>---------------EDIT------------</p>
  
  <p>This is more of the code.</p>
  
  <pre><code>@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." &gt; nul &amp;&amp; set windows=XP
  VER | find  " 5.2." &gt; nul &amp;&amp; set windows=XP 64-Bit or Server 2003 or Server 2003 R2 
  VER | find  " 6.0." &gt; nul &amp;&amp; set windows=Vista or server 2008
  VER | find  " 6.1." &gt; nul &amp;&amp; set windows=Win7 or server 2008 R2
  VER | find  " 6.2." &gt; nul &amp;&amp; set windows=Windows 8
  VER | find  " 6.3." &gt; nul &amp;&amp; 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.
  </code></pre>
  
  <p>-----------------------------edit 3 ------------------<br>
  DONE</p>