N
N
Niko True2015-11-02 04:15:08
cmd/bat
Niko True, 2015-11-02 04:15:08

How to check if a network folder is mounted?

There is a machine on which several disks are mounted, but some may not be connected. The drive letter is unknown. Those. any folder can be mounted to any drive. The remount option is not considered. It is necessary to determine which disk is not connected and mount it. I did not find adequately working scripts on the Internet. I would like not a crutch, but a normal solution - checked, if not mounted - connected. The snag is how to check if it is connected or not.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey S., 2015-11-02
@buloshnik

or iterate over paths from net use

@echo off
net use >netuse.tmp
SET DISK1=OFF
SET DISK2=OFF
SET DISK3=OFF

FOR /F "tokens=*" %%a in ('findstr.exe "\\\\192.168.0.111\\all" netuse.tmp') DO (
SET DISK1=ON
)
FOR /F "tokens=*" %%a in ('findstr.exe "\\\\192.168.0.111\\backup" netuse.tmp') DO (
SET DISK2=ON
)
FOR /F "tokens=*" %%a in ('findstr.exe "\\\\192.168.0.111\\ro" netuse.tmp') DO (
SET DISK3=ON
)
if "%DISK1%" == "OFF" (net use ? \\192.168.0.111\all)
if "%DISK2%" == "OFF" (net use ? \\192.168.0.111\backup)
if "%DISK3%" == "OFF" (net use ? \\192.168.0.111\ro)

without temp file:
@echo off
set a=NO
FOR /F %%a in ('net use ^| findstr.exe "\\\\192.168.0.111\\all"') DO (
set a=%%a
)

if "%a%"=="OK" GOTO NEXT2
net use ? \\192.168.0.111\all
:NEXT2

set a=NO
FOR /F %%a in ('net use ^| findstr.exe "\\\\192.168.0.111\\backup"') DO (
set a=%%a
)

if "%a%"=="OK" GOTO NEXT3
net use ? \\192.168.0.111\backup
:NEXT3

set a=NO
FOR /F %%a in ('net use ^| findstr.exe "\\\\192.168.0.111\\ro"') DO (
set a=%%a
)

if "%a%"=="OK" GOTO NEXT4
net use ? \\192.168.0.111\ro
:NEXT4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question