我正在研究一个WinPE磁盘,它要求我在命令提示符下向用户列出磁盘的字母和标签。不幸的是,WMIC logicaldisk ...
在我的WinPE环境中给了我一个错误,因此我拼凑了几行“复制”WMIC
所做的事情。代码如下:
for /f "delims=" %%i in ('echo :') do set colon=%%i
set drivetmp=%%a
set driveletter=%drivetmp%%colon%
echo Listing drives:
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
fsutil fsinfo volumeinfo %driveletter% > tmpfile.t
find "Volume Name" tmpfile.t >nul && set /p %vname% =< tmpfile.t
find "Volume Name" tmpfile.t >nul && echo . Drive Letter: %driveletter% ..... %vname%
del /q tmpfile.t
)
代码“有效”,但是,对于每一行,它都会打印相同的%vname%
变量。例如,如果我的C:驱动器名为Deployed Drive C
并且我有驱动器C, D, E, F, H and I
,则输出将如下所示:
C:\>test.cmd
Listing drives:
. Volume Label: c: ..... Volume Name : Deployed Drive C
. Volume Label: d: ..... Volume Name : Deployed Drive C
. Volume Label: e: ..... Volume Name : Deployed Drive C
. Volume Label: f: ..... Volume Name : Deployed Drive C
. Volume Label: h: ..... Volume Name : Deployed Drive C
. Volume Label: i: ..... Volume Name : Deployed Drive C
驱动器号按预期更改,缺少的驱动器按预期排除,如果我手动键入命令,它也可以工作!但是,无论我将变量%vname%
或%a%
更改为什么,脚本仍然执行相同的操作。有什么明显的东西让我失踪吗?
答案 0 :(得分:1)
看看这是否符合您的要求:
@echo off
echo Listing drives:
for %%a in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
if exist "%%a:\" (
for /f "tokens=5,*" %%b in ('vol %%a: ^|find /i /v " serial number "') do echo Drive Letter: %%a: Volume Name: %%c
)
)
pause