从分区索引中获取驱动器号

Get the drive letter from Partition Index

我想从分区索引中获取盘符。

wmic path Win32_LogicalDiskToPartition WHERE Antecedent='Win32_DiskPartition.DeviceID=\'Disk #1 AND Partition #0\'' Get Dependent

结果:没有可用的实例

下面应该输出你的信息,你显然需要进一步解析它 select 来自那个的驱动器号。

WMIC Partition Where (DeviceID="Disk #1, Partition #0") Assoc /ResultRole:Dependent 2>NUL

或者:

WMIC Partition Where (DeviceID="Disk #1, Partition #0") Assoc /AssocClass:Win32_LogicalDiskToPartition 2>NUL
SETLOCAL
FOR /F "delims=" %%a in ('wmic path Win32_DiskPartition WHERE (DeviceID="Disk #0, Partition #1") Assoc:list /AssocClass:Win32_LogicalDiskToPartition /ResultRole:Dependent ^| Find "Caption="') DO (
    ECHO %%a
)
Pause

显示为空

我需要结果为:Caption=C: