如何将卷序列号编程为批处理文件的变量?

时间:2018-01-15 22:55:49

标签: windows batch-file

此Win7批处理文件代码检索计算机上所有驱动器的序列号,然后在命令窗口中显示它们 我无法仅隔离运行代码的驱动器%~d0,并将volumeserialnumber捕获到%variable_%

rem -----------Test volumeSerialNumber.BAT------------------

@echo off
wmic logicaldisk where drivetype=3 get volumeserialnumber
pause

for /F "skip=1 delims=" %%j in ("wmic logicaldisk where deviceid = '%~d0' get volumeserialnumber") do (
  set SERIAL=%%j
  goto :DONE
)
:DONE
echo  SERIAL=%SERIAL%
echo %SERIAL%
pause

if "%SERIAL%"=="The Serial Number of Drive C" (
   echo "Success!"
)

1 个答案:

答案 0 :(得分:1)

看起来你只需要更改一些单引号和双引号。

尝试:

For /F "Skip=1 Delims=" %%j In ('WMIC LogicalDisk Where "DeviceID='%~d0'" Get VolumeSerialNumber') Do ...