我正在检测我们的专有USB设备何时连接到PC . 当我们检测到这个时,我们得到相关的 Win32_PnPEntity . 我们想将此 Win32_PnPEntity 用作以下信息的来源:

  • USB描述符VID,PID,REV,固件版本 .
  • 逻辑磁盘驱动器卷和分区信息以获取驱动器号信息 .

我遇到的问题是试图弄清楚如何使用WMI和WMQ从 Win32_PnPEntity 获取逻辑磁盘和分区信息 . Win32_PnPEntityService 类型 USBSTOR (我认为USB存储?)

以下是我目前正在进行的流程的描述:

我使用事件监视器监听 Win32_USBControllerDevice ,以便检测USB设备何时与PC连接或分离 . 我使用以下查询来约束事件中发生的事情:

“SELECT * FROM InstanceOperationEvent WITHIN 1 WHERE TargetInstance ISA'Win32_USBControllerDevice'和TargetInstance . RELPATH LIKE'%DeviceId =%VID_1111%'”

当此事件发生时,我使用 Win32_PNPEntity 类拉出“ Win32_USBControllerDevice.Dependent " property and pull out the " DeviceId " value. I then use this " DeviceId ”值以获取关联的实例 .

对我来说,事情变得棘手......

我需要到 Win32_PnPEntity 实例所涉及的 Win32_DiskDrive . 我需要这个实例以获取卷信息,因此我可以获取每个分区的驱动器号 . 但我不知道如何达到它 .

我经历了这个过程,因为 Win32_PnPEntity 提供了VID,PID用于事件监听和搜索的约束......但它也提供了我需要的固件版本 . 所以从这一点来说,我想得到 Win32_PnPEntityWin32_PnPEntity .

任何输入将不胜感激 .

---提供更好的信息描述问题:

我到目前为止所采取的步骤如下:

  • 收听'__InstanceModificaitionEvent'的'Win32_USBControllerDevice'
  • 从'__InstanceModificaitionEvent'的'TargetInstnace'获取'Win32_PnPEntity'
  • 从包含PID,VID信息的'Win32_PnPEntity'获取'DeviceId' .

我现在的问题是试图找到'Win32_LogicalDisk'和/或'Win32_DiskDrive'和/或'Win32_DiskPartition'或其他一些ASSOCIATOR或REFERENCES链接到USB设备附加的驱动器号已被分配给'Mass Storge'实例 .

我可以想到这个问题的最佳方式在下面的“图表”中描述:

USB DEVICE  
          |         |  
----------|         |----  
| Win32_DiskDrive       | Win32_PnPEntity

我想要做的是弄清楚如何从USB设备的'Win32_PnPEntity'表示到'Win32_DiskDrive'表示 .

以下是我运行的powershell脚本,同时附加了设备 . 它为我提供了属于USB设备的所有实例 . 我知道它们属于同一个设备,因为我只连接了其中一个设备,并且我自定义编辑USB DESCRIPTOR我知道会发生什么 .


PS C:\ Users \ USER.DOMAIN> gwmi Win32_PNPEntity |? {($ _ . DeviceId -match'VEN_MYCOMPANY&') - 或($ _ . DeviceId -match'VID_XXXX')}

__GENUS:2
__CLASS:Win32_PnPEntity
__SUPERCLASS:CIM_LogicalDevice
__DYNASTY:CIM_ManagedSystemElement
__RELPATH:Win32_PnPEntity.DeviceID = "USB\VID_XXXX&PID_0001\YYYY"
__PROPERTY_COUNT:24
__DERIVATION:{CIM_LogicalDevice,CIM_LogicalElement,CIM_ManagedSystemElement}
__SERVER:BYDEFAULT
__NAMESPACE:root \ cimv2
__PATH:\ BYDEFAULT \ root \ cimv2:Win32_PnPEntity.DeviceID = "USB\VID_XXXX&PID_0001\YYYY"
可用性 :
文字说明:USB大容量存储设备
ClassGuid:{36fc9e60-c465-11cf-8056-444553540000}
CompatibleID:{USB \ Class_08&SubClass_06&Prot_50,USB \ Class_08&SubClass_06,USB \ Class_08}
ConfigManagerErrorCode:0
ConfigManagerUserConfig:错误
CreationClassName:Win32_PnPEntity
描述:USB大容量存储设备
DeviceID:USB \ VID_XXXX&PID_0001 \ YYYY
ErrorCleared:
错误描述:
硬件ID:{USB \ VID_XXXX&PID_0001&REV_0001,USB \ VID_XXXX&PID_0001}
InstallDate:
LastErrorCode:
制造商:兼容的USB存储设备
名称:USB大容量存储设备
PNPDeviceID:USB \ VID_XXXX&PID_0001 \ YYYY
PowerManagementCapabilities:
PowerManagementSupported:
服务:USBSTOR
状态:好的
StatusInfo:
SystemCreationClassName:Win32_ComputerSystem
SystemName:BYDEFAULT

__GENUS:2
__CLASS:Win32_PnPEntity
__SUPERCLASS:CIM_LogicalDevice
__DYNASTY:CIM_ManagedSystemElement
__RELPATH:Win32_PnPEntity.DeviceID = "WPDBUSENUMROOT\UMB\2&37C186B&0&STORAGE#VOLUME#??USBSTOR#DISK&VEN_MYCOMPANY&PROD_ZZZZ-STORAGE&REV_5678#YYYY&0#"
__PROPERTY_COUNT:24
__DERIVATION:{CIM_LogicalDevice,CIM_LogicalElement,CIM_ManagedSystemElement}
__SERVER:BYDEFAULT
__NAMESPACE:ROOT \ CIMV2
__PATH:\ BYDEFAULT \ root \ cimv2:Win32_PnPEntity.DeviceID = "WPDBUSENUMROOT\UMB\2&37C186B&0&STORAGE#VOLUME#
??USBSTOR#DISK&VEN_MYCOMPANYI&PROD_ZZZZ-STORAGE&REV_5678#YYYY&0#"
可用性 :
文字说明:ZZZZ
ClassGuid:

CompatibleID:{wpdbusenum \ fs}
ConfigManagerErrorCode:10
ConfigManagerUserConfig:错误
CreationClassName:Win32_PnPEntity
描述:MYCOMPANY - 存储
DeviceID:WPDBUSENUMROOT \ UMB \ 2&37C186B&0&STORAGE #VOLUME #
?? _ USBSTOR #DISK&VEN_MYCOMPANY&PROD_ZZZZ - STORAGE&REV_5678 #YYYY&0#
ErrorCleared:
错误描述:
硬件ID:
InstallDate:
LastErrorCode:
制造商:MYCOMPANY
名称:ZZZZ
PNPDeviceID:WPDBUSENUMROOT \ UMB \ 2&37C186B&0&STORAGE #VOLUME #
?? _ USBSTOR #DISK&VEN_MYCOMPANY&PROD_ZZZZ - STORAGE&REV_5678 #YYYY&0#
PowerManagementCapabilities:
PowerManagementSupported:
服务:WUDFRd
状态:错误
StatusInfo:
SystemCreationClassName:Win32_ComputerSystem
SystemName:BYDEFAULT

__GENUS:2
__CLASS:Win32_PnPEntity
__SUPERCLASS:CIM_LogicalDevice
__DYNASTY:CIM_ManagedSystemElement
__RELPATH:Win32_PnPEntity.DeviceID = "STORAGE\VOLUME_??USBSTOR#DISK&VEN_MYCOMPANY&PROD_ZZZZ-_STORAGE&REV_5678#YYYY&0#{53F56307-B6BF-11D0-94F2-00A0C91EFB8B}"
__PROPERTY_COUNT:24
__DERIVATION:{CIM_LogicalDevice,CIM_LogicalElement,CIM_ManagedSystemElement}
__SERVER:BYDEFAULT
__NAMESPACE:root \ cimv2
__PATH:\ BYDEFAULT \ root \ cimv2:Win32_PnPEntity.DeviceID = "STORAGE\VOLUME_??USBSTOR#DISK&VEN_MYCOMPANY&PROD_ZZZZ-_STORAGE&REV_5678#YYYY&0#{53F56307-B6BF-11D0-94F2-00A0C91EFB8B}"
可用性 :
文字说明:通用卷
ClassGuid:{71a27cdd-812a-11d0-bec7-08002be2092f}
兼容ID:
ConfigManagerErrorCode:0
ConfigManagerUserConfig:错误
CreationClassName:Win32_PnPEntity
描述:通用卷
DeviceID:STORAGE \ VOLUME _ ?? _ USBSTOR #DISK&VEN_MYCOMPANY&PROD_ZZZZ - STORAGE&REV_5678 #YYYY&0#{53F56307-B6BF-11D0-94F2-00A0C91EFB8B}
ErrorCleared:
错误描述:
HardwareID:{STORAGE \ Volume}
InstallDate:
LastErrorCode:
制造商:微软
名称:通用卷
PNPDeviceID:STORAGE \ VOLUME _ ?? _ USBSTOR #DISK&VEN_MYCOMPANY&PROD_ZZZZ - STORAGE&REV_5678 #YYYY&0#{53F56307-B6BF-11D0-94F2-00A0C91EFB8B}
PowerManagementCapabilities:
PowerManagementSupported:
服务:volsnap
状态:好的
StatusInfo:
SystemCreationClassName:Win32_ComputerSystem
SystemName:BYDEFAULT

GENUS : 2 __CLASS : Win32_PnPEntity __SUPERCLASS : CIM_LogicalDevice __DYNASTY : CIM_ManagedSystemElement _RELPATH : Win32_PnPEntity.DeviceID="USBSTOR\DISK&VEN_MYCOMPANY&PROD_ZZZZ-_STORAGE&REV_5678\YYYY&0" __PROPERTY_COUNT : 24 __DERIVATION : {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement} __SERVER : BYDEFAULT __NAMESPACE : root\cimv2 _PATH : \BYDEFAULT\root\cimv2:Win32_PnPEntity.DeviceID="USBSTOR\DISK&VEN_MYCOMPANY&PROD_ZZZZ-STORAGE&REV_5678\YYYY&0" Availability : Caption : MYCOMPANY ZZZZ - Storage USB Device ClassGuid : {4d36e967-e325-11ce-bfc1-08002be10318} CompatibleID : {USBSTOR\Disk, USBSTOR\RAW} ConfigManagerErrorCode : 0 ConfigManagerUserConfig : False CreationClassName : Win32_PnPEntity Description : Disk drive DeviceID : USBSTOR\DISK&VEN_MYCOMPANY&PROD_ZZZZ-STORAGE&REV_5678\YYYY&0 ErrorCleared : ErrorDescription : HardwareID : {USBSTOR\DiskMYCOMPANY___ZZZZ-Storage5678, USBSTOR\DiskMYCOMPANY___ZZZZ-Storage, USBSTOR\DiskMYCOMPANY ,USBSTOR \ MYCOMPANY ___ ZZZZ - Storage5 ...}
InstallDate:
LastErrorCode:
制造商:(标准磁盘驱动器)
名称:MYCOMPANY ZZZZ - 存储USB设备
PNPDeviceID:USBSTOR \ DISK&VEN_MYCOMPANY&PROD_ZZZZ - STORAGE&REV_5678 \ YYYY&0
PowerManagementCapabilities:
PowerManagementSupported:
服务:磁盘
状态:好的
StatusInfo:
SystemCreationClassName:Win32_ComputerSystem
SystemName:BYDEFAULT


上面的结果集显示了很多信息 .

结果1 - 'SERVICE TYPE'是'USBSTOR' . 这是我想在收听'__InstanceModificaitionEvent'时使用的Win32_PnPEntity,因为它给了我VID和PID .
结果2 - 我不感兴趣的复合设备表示 .
结果3 - 'SERVICE TYPE'是'volsnap' . 这是卷实体,我对此感兴趣 .
结果4 - 'SERVICE TYPE'是'disk' . 这是磁盘实体,我对此感兴趣 .

如何获得“结果1”和“结果3”和/或“结果4”之间的关系?

我曾尝试使用'Win32_PnPDevice'关联类,但它似乎没有让我达到我需要的程度 . 我是这个PowerShell WMI和WMQ环境的新手,所以我很可能没有正确使用'Win32_PnPDevice' .

我运行以下查询来确定相关“Win32_PnPDevice”实体的“SameElement”和“SystemElement”属性上的内容:

gwmi Win32_PNPDevice |%{[wmi]($ . SameElement)} | select {$ .Name,$ . Description,$ .DeviceId,$ _ . Status} gwmi Win32_PNPDevice |%{[wmi]($ . SystemElement)} |选择{$ .Name,$ .Description,$ .DeviceId,$ _ . 状态}

结果可以理解如下:

Win32_PNPDevice.SameElement - {PHYSICALDRIVE1,磁盘驱动器,PHYSICALDRIVE1,OK} Win32_PNPDevice.SystemElement - {MYCOMPANY ZZZZ - 存储USB设备,磁盘驱动器,USBSTOR_DISK&VEN_MYCOMPANY&PROD_ZZZZ _-_存储&REV_5678_YYYY&0,OK} Win32_PNPDevice.SameElement - {USB大容量存储设备,USB大容量存储设备,USB_VID_XXXX&PID

YYYY,OK} Win32_PNPDevice.SystemElement - {USB大容量存储设备,USB大容量存储设备,USB_VID_XXXX&PID

YYYY,OK}

也许我错误地使用了'Win32_PnPDevice'类,但似乎我无法将'Win32_PnPEntity'连接到'Win32_DiskDrive'......

我希望这些额外的信息更能描述我的问题 .