Sign in to follow this  
Followers 0
Dougiefresh

[Solved] Need help telling USB Devices apart....

4 posts in this topic

#1 ·  Posted (edited)

I found some code at USB Mass Storage Monitor topic and am needing some assistance.

Here is my modified version of ChrisL's code:

Func _DrivesFromBusType( $Bus = "" )
    Local $aDletters = "", $strComputer = "."
    Local $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
    Local $colDiskDrives = $objWMIService.ExecQuery("SELECT * FROM Win32_DiskDrive")
     
    For $objDrive In $colDiskDrives
        If $Bus <> "" and $objDrive.InterfaceType <> $Bus then Continueloop
        ConsoleWrite( "Physical Disk: " & $objDrive.Caption & " -- " & $objDrive.DeviceID & " (" & $objDrive.InterfaceType & ")" &  @crlf)
        $strDeviceID = StringReplace($objDrive.DeviceID, "\", "\\")
        ConsoleWrite( $objDrive.DeviceID & " = " & $objDrive.PNPDeviceID & @CRLF )
        Local $colPartitions = $objWMIService.ExecQuery( "ASSOCIATORS OF {Win32_DiskDrive.DeviceID=""" & _
                $strDeviceID & """} WHERE AssocClass = Win32_DiskDriveToDiskPartition" )
        For $objPartition In $colPartitions
            ConsoleWrite( "Disk Partition: " & $objPartition.DeviceID & @crlf)
            Local $colLogicalDisks = $objWMIService.ExecQuery( "ASSOCIATORS OF {Win32_DiskPartition.DeviceID=""" & _
                    $objPartition.DeviceID & """} WHERE AssocClass = Win32_LogicalDisk " & $Floppy )
            For $objLogicalDisk In $colLogicalDisks
                ConsoleWrite( "Logical Disk: " & $objLogicalDisk.DeviceID & @crlf)
                $aDletters = $aDletters & $objLogicalDisk.DeviceID & "|"
            Next
        Next
    Next
    Return $aDletters
EndFunc
The _DrivesFromBusType takes one parameter and returns a string of drives delimited by "|". Valid parameters seem to be "IDE", "USB", and "1394" (FireWire). Passing no parameter to the function gets all fixed drive letters attached to the system.

However, here is my problem. First, here is the console output from the above code:

Physical Disk: Generic USB CF Reader USB Device -- \\.\PHYSICALDRIVE3 (USB)
\\.\PHYSICALDRIVE3 = USBSTOR\DISK&VEN_GENERIC&PROD_USB_CF_READER&REV_1.01\9205291&1
Physical Disk: Generic USB MS Reader USB Device -- \\.\PHYSICALDRIVE5 (USB)
\\.\PHYSICALDRIVE5 = USBSTOR\DISK&VEN_GENERIC&PROD_USB_MS_READER&REV_1.03\9205291&3
Physical Disk: Generic USB SD Reader USB Device -- \\.\PHYSICALDRIVE2 (USB)
\\.\PHYSICALDRIVE2 = USBSTOR\DISK&VEN_GENERIC&PROD_USB_SD_READER&REV_1.00\9205291&0
Physical Disk: Generic USB SM Reader USB Device -- \\.\PHYSICALDRIVE4 (USB)
\\.\PHYSICALDRIVE4 = USBSTOR\DISK&VEN_GENERIC&PROD_USB_SM_READER&REV_1.02\9205291&2

Now, I've also got a piece of code that returns information from the HKLM\SYSTEM\MountedDevices key. Here it is:

$usbdev = RegRead( "HKLM\SYSTEM\MountedDevices", "\DosDevices\" & $Drv )
$usbdev = _HexToString( StringReplace( $usbdev, "00", "" ) )
ConsoleWrite( "Drive " & $Drv & " = " & $UsbDev & @CRLF )
Where $Drv is the drive letter being questioned.

The output of the above code for the USB is this:

Drive u: = \??\STORAGE#RemovableMedia#7&37786a0b&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
Drive v: = \??\STORAGE#RemovableMedia#7&23415857&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
Drive w: = \??\STORAGE#RemovableMedia#7&168e5ac5&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}
Drive x: = \??\STORAGE#RemovableMedia#7&7ad55db&0&RM#{53f5630d-b6bf-11d0-94f2-00a0c91efb8b}

How do I associate a drive letter with a USB device description passed back by WMI? I know each of the above drives are one of the slots on my card reader. Any assistance would be greatly appreciated!

Edited by Dougiefresh

Share this post


Link to post
Share on other sites

ChrisL's code is *supposed* to print the name physical disk (\.\PHYSICALDRIVE3) then the name disk partitions then the names of logical drives for the disk partitions (u:, v:, etc).

Probabily the reason why you don't have the disk partition/logical drive information printed out is because the media is not inserted. (i.e. you don't haveSD/SM/CF cards in their respective slots)

#)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

DOH! Let me try that.... I should have tried that first! On second thought, if that was the case, why does my MP3 player do the same thing? It's formatted and ready to write to as a removable drive.

EDIT: After inserting a 1GB SD card, here's the information I get on the SD reader:

Physical Disk: Generic USB SD Reader USB Device -- \\.\PHYSICALDRIVE2 (USB)
\\.\PHYSICALDRIVE2 = USBSTOR\DISK&VEN_GENERIC&PROD_USB_SD_READER&REV_1.00\9205291&0
Disk Partition: Disk #2, Partition #0
No logical partition information is given in the output. Edited by Dougiefresh

Share this post


Link to post
Share on other sites

I've opened another topic requesting assistance translating some code I found on the internet. I think it will provide me with the answers I'm seeking.... (I hope) Thanks for the assistance!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0