3

I need to check if a drive (Z:) is in use (e.g. in use by an application, opened).

My Batch File looks like this:

Mount Z:
wait 15 minutes
check if drive Z: is in use

IF NOT: unmount Z:
ELSE: wait 15 minutes
repeat..

Is there any Command for this? Thanks!

Jan Levers
  • 31
  • 1
  • 4

3 Answers3

2

Use the IF EXIST or IF NOT EXIST combination:

:FindDrive
if exist Z:\nul goto Mounted
timeout /T 5
goto FindDrive
:Mounted

NUL is the a 'virtual' file that exists in every folder. So if c:\anypath\nul exists, the drive exists.

James K
  • 4,005
  • 4
  • 20
  • 28
  • This checks the existence of the drive, but not (as the OP asks) if the drive is in use, thats much more tricky – jeb Jul 17 '12 at 06:44
1
@echo off
echo --------------------------------------------------
echo Checking if Y:\10.210.12.8\Rubicon Drive exist? Please wait...
echo IMPORTANT: DO NOT TOUCH THE COMPUTER DURING THIS PROCESS
echo --------------------------------------------------
Rem : Bill Kingsley

SET LOG=c:\Temp\logs

echo **********[%Date% - %Time%****************>%LOG%\Mapdrive.log

  IF EXIST Y:\  (
        echo. 
    echo The drive is already mapped. 
    echo ...Check if the mapp drive is accessible?....
        echo.
    dir y: >>%LOG%\Mapdrive.log
    if ERRORLEVEL 1 GOTO MAPDRIVE     
        GOTO SKIPPED
    ) ELSE (
      echo The drive has not yet been mapped.
      goto MAPDRIVE   
      )
goto end


:SKIPPED
echo.
Echo ******Mapped Drive Y is working Fine********
Echo.
Goto end

:MAPDRIVE
Net use Y: /d
net use Y: \\172.31.161.100\eBBS 
      dir Y: >> %LOG%\Mapdrive.log
  if errorlevel 0 goto SKIPPED
  if errorlevel 1 goto MAPDRIVE  
Goto end

:end 
echo ----------------------------------------
echo Maintenance check complete. check log in %LOG%
echo ----------------------------------------
rem exit
McDowell
  • 107,573
  • 31
  • 204
  • 267
0

If you have your power options set correctly It will stop the patter from spinning if it is not in use.

In windows 7, in your start search for power options. In your current power plan hit change plan options. then hit change advanced power options and go to hard drive.

http://blog.laptopmag.com/windows-advanced-power-options-explained

Zain
  • 21
  • 2