Getting the PhysicalDrive for the LogicalDisk!

  • Thread starter Thread starter Matthias Pfeffer
  • Start date Start date
M

Matthias Pfeffer

Hello!

I'm working with some USB Events (arrive and remove) using the
ManagementBaseObject!
It works fine, but i need the relation between the physical drive
(\.\\PHYSICALDRIVE0) and the logical drive ("C:").

Is there any possibility to get the physical drive from logical disk c: or
d:?


thx for help!


michael
 
Matthias Pfeffer said:
Hello!

I'm working with some USB Events (arrive and remove) using the
ManagementBaseObject!
It works fine, but i need the relation between the physical drive
(\.\\PHYSICALDRIVE0) and the logical drive ("C:").

Is there any possibility to get the physical drive from logical disk c: or
d:?


thx for help!


michael

You have to walk the associaters chain starting from the logicaldisk over
the associated partition(s)down to the phyiscal disk.

Something like this will do....

using(ManagementObject mo = new ManagementObject(
@"Win32_LogicalDisk='D:'"))
{
foreach (ManagementObject b in mo.GetRelated("Win32_DiskPartition"))
{
foreach (ManagementBaseObject c in b.GetRelated("Win32_Diskdrive"))
Console.WriteLine("{0}", c["Name"]);
}
}

Note that it takes some extra time to scan the DiskDrive chain on system
with floppy drives.

Willy.
 
hi willy!

thanks for your help!
it works! :o)

greetz

Willy Denoyette said:
Matthias Pfeffer said:
Hello!

I'm working with some USB Events (arrive and remove) using the
ManagementBaseObject!
It works fine, but i need the relation between the physical drive
(\.\\PHYSICALDRIVE0) and the logical drive ("C:").

Is there any possibility to get the physical drive from logical disk c: or
d:?


thx for help!


michael

You have to walk the associaters chain starting from the logicaldisk over
the associated partition(s)down to the phyiscal disk.

Something like this will do....

using(ManagementObject mo = new ManagementObject(
@"Win32_LogicalDisk='D:'"))
{
foreach (ManagementObject b in mo.GetRelated("Win32_DiskPartition"))
{
foreach (ManagementBaseObject c in b.GetRelated("Win32_Diskdrive"))
Console.WriteLine("{0}", c["Name"]);
}
}

Note that it takes some extra time to scan the DiskDrive chain on system
with floppy drives.

Willy.
 
Back
Top