3

我需要检查驱动器 (Z:) 是否正在使用中(例如,正在被应用程序使用,已打开)。

我的批处理文件如下所示:

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

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

有什么命令吗?谢谢!

4

3 回答 3

2

使用IF EXISTIF NOT EXIST组合:

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

NUL 是存在于每个文件夹中的“虚拟”文件。因此,如果 c:\anypath\nul 存在,则驱动器存在。

于 2012-07-17T05:29:21.680 回答
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
于 2014-04-03T20:23:01.470 回答
0

如果您的电源选项设置正确,它会在不使用时停止模式旋转。

在 Windows 7 中,在您的开始搜索电源选项。在您当前的电源计划中点击更改计划选项。然后点击更改高级电源选项并转到硬盘驱动器。

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

于 2012-07-15T21:53:51.487 回答