View Single Post
Old 10-19-2007, 06:58 PM   #21
smcclain
Junior Member
smcclain began at the beginning.
 
Posts: 1
Karma: 28
Join Date: Oct 2007
Location: Los Angeles, CA
Device: PRS-505
WMI VBS script example

You should be able to use windows WMI api to get the info... here's and example VBS script I found on MSDN that enumerates the physical drives on the system and determines the drive letter. Simply save the the code to a text file and give the file a .vbs extension and you sould be able to run in in windows just by double clicking it. Hope this helps you.

Code:
ComputerName = "."
Set wmiServices  = GetObject ( _
    "winmgmts:{impersonationLevel=Impersonate}!//" _
    & ComputerName)
' Get physical disk drive
Set wmiDiskDrives =  wmiServices.ExecQuery ( _
    "SELECT Caption, DeviceID, PNPDeviceID FROM Win32_DiskDrive")

For Each wmiDiskDrive In wmiDiskDrives
    WScript.Echo "Disk drive Caption: " _
        & wmiDiskDrive.Caption _ 
        & VbNewLine & "PNPDeviceID: " _
        & " (" & wmiDiskDrive.PNPDeviceID & ")"

    'Use the disk drive device id to
    ' find associated partition
    query = "ASSOCIATORS OF {Win32_DiskDrive.DeviceID='" _
        & wmiDiskDrive.DeviceID & "'} WHERE AssocClass = Win32_DiskDriveToDiskPartition"    
    Set wmiDiskPartitions = wmiServices.ExecQuery(query)

    For Each wmiDiskPartition In wmiDiskPartitions
        'Use partition device id to find logical disk
        Set wmiLogicalDisks = wmiServices.ExecQuery _
            ("ASSOCIATORS OF {Win32_DiskPartition.DeviceID='" _
             & wmiDiskPartition.DeviceID & "'} WHERE AssocClass = Win32_LogicalDiskToPartition") 

        For Each wmiLogicalDisk In wmiLogicalDisks
            WScript.Echo "Drive letter associated" _
                & " with disk drive = " _ 
                & wmiDiskDrive.Caption _
                & wmiDiskDrive.PNPDeviceID _
                & VbNewLine & " Partition = " _
                & wmiDiskPartition.DeviceID _
                & VbNewLine & " is " _
                & wmiLogicalDisk.DeviceID
        Next      
    Next
Next
smcclain is offline   Reply With Quote