如何从BIOS获取序列号并使用Windows批处理命令将其与一组其他序列号进行比较?

时间:2013-11-13 00:36:28

标签: batch-file

我有一个100+序列号的列表。 我想要做的是:检查我正在处理的计算机的序列号是否在列表中。 是否可以在Windows批处理脚本中执行此操作?

3 个答案:

答案 0 :(得分:1)

此命令行显示计算机中的BIOS SerialNumber(Windows 8):

for /F "skip=1 tokens=3" %s in ('wmic bios list BRIEF') do echo %s

您可以测试并调整它直到得到您想要的。例如:

@echo off
for /F "skip=1 tokens=3" %%s in ('wmic bios list BRIEF') do set serial=%%s
for /F "delims=" %%s in (serialList.txt) do if "%%s" equ "%serial%" goto found
echo Not found
goto :EOF

:found
echo OK

编辑:我修改了程序,以便在批处理文件中包含序列号;我还使用了Stephan建议的wmic参数中的修改:

@echo off
for /F "tokens=2 delims==" %%s in ('wmic bios get serialnumber /value') do set serial=%%s
for %%s in (serial0 serial1 serial2 serial3 serial4 serial5 serial6 serial7 serial8 serial9
            ser90 ser91 ser92 ser93 ser94 ser95 ser96 ser97 ser98 ser99 ser100 ser101) do (
   if "%%s" equ "%serial%" goto found
)
echo Not found
goto :EOF

:found
echo OK

答案 1 :(得分:1)

无需遍历文件中的每一行:

@echo off
for /F "tokens=2 delims==" %%s in ('wmic bios get serialnumber /value') do ( 
  findstr "%%s" serials.txt
  )
if %errorlevel%==0 ( echo Serialnumber found ) else ( echo Serialnumber not listed )

答案 2 :(得分:0)

如果您使用列表作为搜索字符串并将WMIC BIOS输出作为目标,则不需要FOR循环。我相信序列号总是10个字符,因此不需要/I选项。但是,如果序列号长度可能不同,则由于FINDSTR错误需要/I选项:Why doesn't this FINDSTR example with multiple literal search strings find a match?

wmic bios get serialNumber|findstr /blg:list.txt&&echo number found||echo number not listed

您可以使用>nul将FINDSTR输出重定向到nul,从而禁止将序列号输出到屏幕。