【问题标题】:MS Batch: Check if drive is in useMS Batch:检查驱动器是否正在使用中
【发布时间】:2012-07-14 19:18:59
【问题描述】:

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

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

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

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

有任何命令吗?谢谢!

【问题讨论】:

  • 这看起来不像一个批处理文件。 MountUnmount 是外部实用程序吗?
  • 我也需要答案。它存在于 StackOverflow 中吗?

标签: scripting batch-file dos


【解决方案1】:

使用 IF EXISTIF NOT EXIST 组合:

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

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

【讨论】:

  • 这会检查驱动器是否存在,但如果驱动器正在使用中则不会(正如 OP 所要求的那样),这更棘手
【解决方案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】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2018-02-18
      • 2015-10-08
      • 2012-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多