Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get logical drive from physical drive? 1

Status
Not open for further replies.

haddaway

Programmer
Jul 6, 2005
172
SE
I am trying to get the "real" hd serial and it's path:

' query the Win32_DiskDrive class first
Dim searcher As New ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive")

For Each wmi_HD As ManagementObject In searcher.Get()
Dim hd As New HDClass
hd.Model = wmi_HD("Model").ToString()
hd.Type = wmi_HD("InterfaceType").ToString()
hd.PhysicalDrive = wmi_HD("DeviceID").ToString()
hd.MediaType = wmi_HD("MediaType").ToString()
hd.Name = wmi_HD("Name").ToString()
hd.SystemName = wmi_HD("SystemName").ToString()
hd.Caption = wmi_HD("Caption").ToString()
hdCollection.Add(hd)
Next

' extract the serial number from Win32_PhysicalMedia class
Dim searcher2 As New ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia")

Dim i As Integer = 0
For Each wmi_HD As ManagementObject In searcher2.Get()
' get the hard drive from collection
' using index
Dim hd As HDClass = DirectCast(hdCollection(i), HDClass)

' get the hardware serial no.
If wmi_HD("SerialNumber") Is Nothing Then
hd.Serial = "None"
Else
hd.Serial = wmi_HD("SerialNumber").ToString()
End If
i += 1
Next

The problem is that I can't get the logical path like "c:", just the physicalpath: \\.\PHYSICALDRIVE0

How can I get the logical drive letter from the physical path?
 
Start with the Win32_DiskDrive class and query for instances of Win32_DiskPartition using the DeviceID property and the Win32_DiskDriveToDiskPartition association class. Now you have a collection of the partitions on the physical drive.
Query for the Win32_LogicalDisk that represents the partition using the Win32_DiskPartition.DeviceID property and Win32_LogicalDiskToPartition association class.
Get the drive letter from the Win32_LogicalDisk.DeviceID.

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top