问题
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!
回答1:
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.
回答2:
@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
回答3:
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
来源:https://stackoverflow.com/questions/11495908/ms-batch-check-if-drive-is-in-use