-
December 22nd, 2008, 04:51 AM
#1
Using WMI to get USB device drive letter
Hi all.
i am using WMI to retrieve the drive letter. Before that i need to retrieve the device ID for the USB devices present .
now i have been able to fetch the device ID, not the PNP device id , but the device id which is got by queryingfrom WIN32_USBHub.
now using this device ID which i received from WIN32_USBHub, i have to retrieve the drive letter. i.e i have to fetch the drive letter from WMI corresponding to the DeviceID which i have with me. bit i am not able to get any perfect mapping for this .
please can i get some help on how to get the drive letter of a USB device from the DeviceID.
Thanks .
-
December 22nd, 2008, 02:16 PM
#2
Re: Using WMI to get USB device drive letter
Looks like you have the HUB but not the device. You can iterate through the devices connected to a hub IIRC...
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 24th, 2008, 12:11 AM
#3
Re: Using WMI to get USB device drive letter
>> not the PNP device id, but the device id ... now using this device ID ... i have to retrieve the drive letter.
Win32_USBHub.DeviceId is the same as Win32_USBHub.PNPDeviceId. This PNP Id isn't the same as the PNP Id of the logical disk. Here's how you can determine which connected USB devices correspond to what logical drives:
Code:
SELECT * FROM Win32_USBControllerDevice
For Each as USBDevice
ASSOCIATORS OF {Win32_PnPEntity.DeviceID="<USBDevice.Dependent>"}
WHERE ResultClass = Win32_DiskDrive
For Each as Drive
ASSOCIATORS OF {Win32_DiskDrive.DeviceID="<Drive.DeviceID>"}
WHERE AssocClass = Win32_DiskDriveToDiskPartition
For Each as Drive2Part
ASSOCIATORS OF {Win32_DiskPartition.DeviceID="<Drive2Part.DeviceID>"}
WHERE AssocClass = Win32_LogicalDiskToPartition
For Each as Disk2Part
Win32_LogicalDisk = <Disk2Part.Dependent>
End For
End For
End For
End For
gg
-
December 31st, 2008, 09:18 PM
#4
Re: Using WMI to get USB device drive letter
I'm pretty new at this, how do I actually run the code below? Do I use Visual Studio, and if so how do I create the project?
Originally Posted by Codeplug
>> not the PNP device id, but the device id ... now using this device ID ... i have to retrieve the drive letter.
Win32_USBHub.DeviceId is the same as Win32_USBHub.PNPDeviceId. This PNP Id isn't the same as the PNP Id of the logical disk. Here's how you can determine which connected USB devices correspond to what logical drives:
Code:
SELECT * FROM Win32_USBControllerDevice
For Each as USBDevice
ASSOCIATORS OF {Win32_PnPEntity.DeviceID="<USBDevice.Dependent>"}
WHERE ResultClass = Win32_DiskDrive
For Each as Drive
ASSOCIATORS OF {Win32_DiskDrive.DeviceID="<Drive.DeviceID>"}
WHERE AssocClass = Win32_DiskDriveToDiskPartition
For Each as Drive2Part
ASSOCIATORS OF {Win32_DiskPartition.DeviceID="<Drive2Part.DeviceID>"}
WHERE AssocClass = Win32_LogicalDiskToPartition
For Each as Disk2Part
Win32_LogicalDisk = <Disk2Part.Dependent>
End For
End For
End For
End For
gg
-
December 31st, 2008, 10:25 PM
#5
Re: Using WMI to get USB device drive letter
>> how do I actually run the code below?
Well, you don't. It's pseudo-code. Most of it is actually taken from a VBS script sample on MSDN:
http://msdn.microsoft.com/en-us/libr...92(VS.85).aspx
See the last "How do I..." example.
>> Do I use Visual Studio
For scripting, all you really need is notepad.
gg
-
December 31st, 2008, 11:20 PM
#6
Re: Using WMI to get USB device drive letter
Originally Posted by Codeplug;1797249>> [b
Do I use Visual Studio[/b]
For scripting, all you really need is notepad.
REAL programmers use:
Code:
C:\>copy con file.sav
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|