"Matthias Pfeffer" <kn*****@gmx.net> wrote in message
news:uN*************@TK2MSFTNGP14.phx.gbl...
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.