I detect when our proprietary USB device is connected to a PC. When we discover this, we get the associated Win32_PnPEntity . We want to use this Win32_PnPEntity as a source of the following information:
- USB descriptor VID, PID, REV, firmware version.
- Logical disk information and partition information to get disk information.
The problem I am facing is trying to figure out how to use WMI and WMQ to access the logical drive and partition information from Win32_PnPEntity .
Win32_PnPEntity has a service type USBSTOR (the USB-drive, I think?)
The following is a description of the process I'm currently looking at:
I am listening to Win32_USBControllerDevice with an event observer to detect when a USB device is connected or disconnected from the PC. I use the following query to limit what happens on an event:
"SELECT * FROM
__InstanceOperationEvent ININ 1 WHERE TargetInstance ISA
" Win32_USBControllerDevice "and
TargetInstance .__ RELPATH LIKE '% DeviceId =% VID_1111%'"
When this event occurs, I pulled out the Win32_USBControllerDevice.Dependent property and pulled out the DeviceId value . Then I use this DeviceId value with the Win32_PNPEntity class to get the associated instance.
Here it becomes difficult for me ...
Win32_DiskDrive, Win32_PnPEntity. , , , . , .
, Win32_PnPEntity VID, PID ... , . Win32_DiskDrive Win32_PnPEntity.
.
--- :
, , :
- "__InstanceModificaitionEvent" "Win32_USBControllerDevice"
- "Win32_PnPEntity" "TargetInstnace" "__InstanceModificaitionEvent"
- "DeviceId" "Win32_PnPEntity" , PID, VID.
, , , "Win32_LogicalDisk" AND/OR "Win32_DiskDrive" AND/OR "Win32_DiskPartition" - ASSOCIATOR REFERENCES , USB- "Mass Storge".
, , "":
USB DEVICE
| |
----------| |----
| Win32_DiskDrive | Win32_PnPEntity
, , - , Win32_PnPEntity USB- "Win32_DiskDrive" .
powershell script, . , 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
__: {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: False
CreationClassName: Win32_PnPEntity
: USB-
DeviceID: USB\VID_XXXX & PID_0001\YYYY
ErrorCleared:
ErrorDescription:
HardwareID: {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
__: {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: {eec5ad98-8080-425f-922a-dabf3de3f69a}
CompatibleID: {wpdbusenum\fs}
ConfigManagerErrorCode: 10
ConfigManagerUserConfig: False
CreationClassName: Win32_PnPEntity
: MYCOMPANY -
DeviceID: WPDBUSENUMROOT\UMB\2 & 37C186B & 0 & # VOLUME #_?? _ USBSTOR # DISK & VEN_MYCOMPANY & PROD_ZZZZ _-_ STORAGE & REV_5678 # YYYY & 0 #
ErrorCleared:
ErrorDescription:
HardwareID:
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 = "\\_?? _ USBSTOR # DISK & VEN_MYCOMPANY & PROD_ZZZZ _-_ STORAGE & REV_5678 # YYYY & 0 # {53F56307-B6BF-11D0-94F2-00A0C91EFB8B}"
__PROPERTY_COUNT: 24
__: {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 # {53F56307-B6BF-11D0-94F2-00A0C91EFB8B}" < > :
:
ClassGuid: {71a27cdd-812a-11d0-bec7-08002be2092f}
CompatibleID:
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_PnPEntity
:
DeviceID: STORAGE\VOLUME _?? _ USBSTOR # DISK & VEN_MYCOMPANY & PROD_ZZZZ _-_ & REV_5678 # YYYY & 0 # {53F56307-B6BF-11D0-94F2-00A0C91EFB8B}
ErrorCleared:
ErrorDescription:
HardwareID: {STORAGE\Volume}
InstallDate:
LastErrorCode:
: Microsoft
:
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
__: {CIM_LogicalDevice, CIM_LogicalElement, CIM_ManagedSystemElement}
__SERVER: BYDEFAULT
__NAMESPACE: root\cimv2
__PATH:\BYDEFAULT\root\cimv2: Win32_PnPEntity.DeviceID = "USBSTOR\DISK & VEN_MYCOMPANY & PROD_ZZZZ _-_ & REV_5678\YYYY & 0"
:
Caption: MYCOMPANY ZZZZ - USB-
ClassGuid: {4d36e967-e325-11ce-bfc1-08002be10318}
CompatibleID: {USBSTOR\Disk, USBSTOR\RAW}
ConfigManagerErrorCode: 0
ConfigManagerUserConfig: False
CreationClassName: Win32_PnPEntity
:
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 - " " - "USBSTOR". Win32_PnPEntity, "__InstanceModificaitionEvent" , VID PID.
2 - Composite Device, .
3 - " " - "volsnap". , .
4 - " " - "". , .
" 1" " 3" / " 4"?
'Win32_PnPDevice', , , . WMI WMQ, , "Win32_PnPDevice" .
, , "SameElement" "SystemElement" "Win32_PnPDevice" :
gwmi Win32_PNPDevice |% {[wmi] ( $. SameElement )} | {$.Name, $.Description, $.DeviceId, $_. }
gwmi Win32_PNPDevice |% {[wmi] ( $. SystemElement )} | {$.Name, $.Description, $.DeviceId, $_. Status}
:
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_0001_YYYY, OK}
Win32_PNPDevice.SystemElement - {USB Mass Storage Device, USB Mass , USB_VID_XXXX & PID_0001_YYYY, OK}
, "Win32_PnPDevice" , , , "Win32_PnPEntity" "Win32_DiskDrive" ...
, .