Начните использовать 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
на что-то вроде
Capabilities DeviceID SerialNumber Bootable
{3, 4} \\.\PHYSICALDRIVE0 NXXXXXXXXK4R2DT True
{3, 4, 7} \\.\PHYSICALDRIVE1 S0NFJNXXXXXXXX