可启动设备的序列号

时间:2019-06-19 09:49:02

标签: windows hard-drive wmic

我必须获取安装了操作系统的磁盘的序列号。

我知道要获取序列号,我需要运行:

>wmic diskdrive get serialnumber,capabilities
Capabilities  SerialNumber
{3, 4}        AI92NXXXXXXXX2G02
{3, 4, 7}     1172XXXXXX030

没有属性可以检查操作系统是否已安装在此磁盘上。

1 个答案:

答案 0 :(得分:1)

开始使用th:object,然后回溯到wmic partition where Bootable=True(一种可能的方法):

Win32_DiskDrive

当然,根据实际输出

@ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
for /F "delims=" %%G in ('
  wmic path Win32_DiskPartition where "Bootable=True" get DeviceID /Value
') do ( 
  for /F "tokens=1* delims==" %%g in ("%%G") do (
    set "_DiskPartition=%%h"
    REM ECHO set "_DiskPartition=%%h"
    call :GetDiskDriveIdAndOutput
  )
)
echo Possibly no linkage to a logical disk:
2>NUL wmic path Win32_LogicalDisk ^
  ASSOC /RESULTROLE:Antecedent ^
        /ASSOCCLASS:Win32_LogicalDiskToPartition ^
        /RESULTCLASS:Win32_DiskPartition  
ENDLOCAL
goto :eof

:GetDiskDriveIdAndOutput
for /F tokens^=^2^ delims^=^" %%B in ('          
    wmic path Win32_DiskPartition where "Bootable=True" ASSOC /ASSOCCLASS:Win32_DiskDriveToDiskPartition
  ') do (
      if NOT "%%B"=="%_DiskPartition%" (
        REM ECHO set "_DiskDriveId=%%B"
        set "_DiskDriveId=%%B"
      )
)
echo Bootable: Drive = "%_DiskDriveId:\\=\%", Partition = "%_DiskPartition%"
wmic path Win32_DiskDrive get Capabilities,DeviceId,SerialNumber
REM wmic path Win32_DiskDrive Where "DeviceId='%_DiskDriveId%'" get Capabilities,DeviceId,SerialNumber
goto :eof

类似

Bootable: Drive = "\\.\PHYSICALDRIVE0", Partition = "Disk #0, Partition #0"
Capabilities  DeviceID            SerialNumber
{3, 4}        \\.\PHYSICALDRIVE0  NXXXXXXXXK4R2DT
{3, 4, 7}     \\.\PHYSICALDRIVE1  S0NFJNXXXXXXXX