I’m trying to create batch file to connect to a home
network appliance storage (NAS). How do I make it to
first ping if NAS is present to “net use: “, if not
present echo NAS is unreachable?
@echo off
ping -n 1 192.168.1.226 rem My_NAS
if ALIVE goto :CONNECT
if UNREACHABLE goto :END
:CONNECT
if exist p: goto drivefound0 else
goto end
:drivefound0
net use p: /del
:end
if exist s: goto drivefound1
goto end
:drivefound1
net use s: /del
:end
net use p: \\airnas\user1 password1 /user:airnas\user1
net use s: \\airnas\public
:END
echo DONE!
set machine=192.168.1.226
ping -n 1 %machine% > nul
if errorlevel 1 goto :failure
goto :CONNECT
:connect
echo Connection to %machine% is OK!
goto :CONNECT
:failure
echo Connection to %machine% failed…
goto :EOF