check network drive status and existence

Dell Inspiron 11z notebook - customizabl...
October 12, 2009 at 09:03:50
Specs: Windows XP
I need a for loop in batch that'll check for a particular network drive i.e. say K: and then checks the status i.e. OK as well as print the share that K: is mapped to i.e. \\server\test1\yeyuh If the drive status is showing disconnected or not present, then echo. drive K: not present..or blah blah ...

so far I have
for /f "tokens=2" %%a in ('net use ^| findstr /r /c:K') echo.%%a

any ideas or suggestions will be appreciated.

See More: check network drive status and existence

Report •

October 12, 2009 at 11:33:37
How about something like this?

@echo off
net use K: >nul
if %errorlevel% neq 0 GOTO NOTOK
ECHO Network drive K is available
Net use K: | findstr "remote name"
Color 40
Echo Network drive K is NOT available

Report •

October 12, 2009 at 12:25:19
Thanks. I modified it a bit and it worked..

@echo off

setlocal enabledelayedexpansion

set drive=K:

net use !drive! >nul
if not ErrorLevel 1 (
echo.Network Drive !drive! is available
net use !drive | findstr "remote name"
)else (
Color 40
echo.Network drive !drive! is unavailable
echo.Please map your !drive! drive and try again.

Report •

October 12, 2009 at 12:28:49
Well the code doesn't check if the status is OK or disconnected.

Any ideas?

Report •

Related Solutions

October 12, 2009 at 12:58:48
((net use %drive%: | findstr /c:"Status            OK") >NUL 2>&1 && @echo Status good) || @echo Status bad

Report •

October 12, 2009 at 14:46:43
can you possibly modify that so that it prints the share name as well i.e. \\server\share


I haven't tested your code but from looking at it. :D but I can see it only prints the status.

Report •

Ask Question