How to get PNP Device Id
-
I am looking a way to get PNP device Id for USB, CDRom, and hard disks, mapped network drives. I know we can get through WMI calls. My project requires not to use WMI and I am looking ways to get the PNP device id through windows native API calls. I figured out that PNP device ids are listed in windows registry "HKLM\SYSTEM\CurrentControlSet\services\{service}\Enum. Where {service} could be CDROM, disk, USBSTOR etc.... I have following questions on this. 1. How can I link back this "PNP device id" to the mounted volume letter? 2. Not finding a way to get "PNP device id" for network mapped drives? 3. Is there any IOCTL call to get the "PNP device id" for any volume or drive? Thanks in advance
-
I am looking a way to get PNP device Id for USB, CDRom, and hard disks, mapped network drives. I know we can get through WMI calls. My project requires not to use WMI and I am looking ways to get the PNP device id through windows native API calls. I figured out that PNP device ids are listed in windows registry "HKLM\SYSTEM\CurrentControlSet\services\{service}\Enum. Where {service} could be CDROM, disk, USBSTOR etc.... I have following questions on this. 1. How can I link back this "PNP device id" to the mounted volume letter? 2. Not finding a way to get "PNP device id" for network mapped drives? 3. Is there any IOCTL call to get the "PNP device id" for any volume or drive? Thanks in advance
Hi, Although the MSDN recommends to *not* use the PnP functions... I have always used CM_Get_DevNode_Registry_Property_Ex[^] with the CM_DRP_HARDWAREID and CM_DRP_COMPATIBLEIDS. Some pretty good PnP information here: [MS-PNPR]: Plug and Play Remote (PNPR) Protocol Specification[^] Best Wishes, -David Delaune
-
Hi, Although the MSDN recommends to *not* use the PnP functions... I have always used CM_Get_DevNode_Registry_Property_Ex[^] with the CM_DRP_HARDWAREID and CM_DRP_COMPATIBLEIDS. Some pretty good PnP information here: [MS-PNPR]: Plug and Play Remote (PNPR) Protocol Specification[^] Best Wishes, -David Delaune
Thanks david for quick answer. I was looking for PNP functions and references you pointed. Definitely these API's looks promising to find PNP device Id. However, how I can map my volume (drive letter) to its PNP device Id. neither of functions actually refer for volume drive letter. thanks- Prashanth
-
Thanks david for quick answer. I was looking for PNP functions and references you pointed. Definitely these API's looks promising to find PNP device Id. However, how I can map my volume (drive letter) to its PNP device Id. neither of functions actually refer for volume drive letter. thanks- Prashanth
Hi Prashanth, If you have a look at the following: System-Defined Device Setup Classes Available to Vendors[^] You will see that the class ID for disk drives is: {4d36e967-e325-11ce-bfc1-08002be10318} You need to call CM_Get_DevNode_Registry_Property_Ex[^] with the disk drive class ID. Have a look at the article by A. Riazi. Enumerate Properties of an Installed Device[^] You should easily be able to modify the code he provides to retrieve the device ID. Best Wishes, -David Delaune
-
Hi Prashanth, If you have a look at the following: System-Defined Device Setup Classes Available to Vendors[^] You will see that the class ID for disk drives is: {4d36e967-e325-11ce-bfc1-08002be10318} You need to call CM_Get_DevNode_Registry_Property_Ex[^] with the disk drive class ID. Have a look at the article by A. Riazi. Enumerate Properties of an Installed Device[^] You should easily be able to modify the code he provides to retrieve the device ID. Best Wishes, -David Delaune
Thanks david for quick reply. I was able to enumerate all the device ID's with the above calls. Definitely this is good progress for what I am looking. However, none of the API's are actually refering the device id to the respective volume drives. For example, if I could enumerate CDRom drives device id's, there is no way to know their volume drive letters. In other way, volume information and corresponding device info are not related with these API's. If you open "Device Manager" and select any disc drive, open properties and then volumes tab, this will not list all the volumes by default. However when you select "Populate", it is displaying all the volumes in the respective drive. This is what exactly I am looking. Either I should know volumes mounted on particular "Device ID" (or) get the device id for a given volume letter. I dont know how "device manager" is populating drives with the device id? Any thoughts or pointers? Thanks- Prashanth Jaligama
-
Thanks david for quick reply. I was able to enumerate all the device ID's with the above calls. Definitely this is good progress for what I am looking. However, none of the API's are actually refering the device id to the respective volume drives. For example, if I could enumerate CDRom drives device id's, there is no way to know their volume drive letters. In other way, volume information and corresponding device info are not related with these API's. If you open "Device Manager" and select any disc drive, open properties and then volumes tab, this will not list all the volumes by default. However when you select "Populate", it is displaying all the volumes in the respective drive. This is what exactly I am looking. Either I should know volumes mounted on particular "Device ID" (or) get the device id for a given volume letter. I dont know how "device manager" is populating drives with the device id? Any thoughts or pointers? Thanks- Prashanth Jaligama
HI David, thanks for all your pointers. I am able to successfully enumerate volumes and their corresponding Device information using SetupDI functions. 1. SetupDI functions will list all devices for given class guid, such as disks, cdroms, volumes. We can also query for its device number using IOCTL_STORAGE_GET_DEVICE_NUMBER. 2. Separately, all volumes can be retrieved using windows APIs, such as GetLogicalDrives, and then we can also query its device number using same IOCTL_STORAGE_DEVICE_NUMBER on drive letter (ex: \\\\?\\c:). Now I mapped device number in setupDI with the device number retrieved using volumes functions, which allows me to get both volume information and also its corresponding device information. Of course, device number does not persist across boots, but my little software will keep refresh to map volume drives and its corresponding device info. thanks- Prashanth Jaligama