批量检查可移动磁盘是否已连接。如果是,请执行另一个命令


0

我知道如何检查是否有可移动磁盘与CMD命令连接

wmic logicaldisk where drivetype=2 get deviceid, volumename, description

但现在我想制作一个批次,检查是否连接了任何可移动磁盘,如果是,那么它将执行另一个命令或运行另一个批处理。

我该怎么做?

Answers:


0

使用以下内容:

wmic logicaldisk where drivetype=2 get deviceid, volumename, description | findstr /C:"Removable Disk"
if %errorlevel% == 0 (
    Rem Put commands in here to run if disk is found
) else (
    Rem Put commands in here to run if disk not found
)

最简单的方法是将批处理文件设置为每隔x分钟在计划任务上运行 - 尽管在“检测到”可移动磁盘之前可能需要多达几分钟。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.