hi
i m using the win32_diskdrive class for detecting a
memory card insertion and removal..and this class
detects memory card(sd card..etc) insertion removal from the device
the deviceid attribute gives me \\.\PHYSICALDRIVE0 or
\\.\PHYSICALDRIVE1
etc..
i m trying to get the drive name say(c: or d: ...etc)from the device
id
attribute returned above..
i found this code on the net which said wud get the
drive letter from the device id..
using(ManagementClass devs = new ManagementClass(
@"Win32_Diskdrive"))
{
ManagementObjectCollection moc = devs.GetInstances();
foreach(ManagementObject mo in moc)
{
Console.WriteLine(mo["DeviceId"]);
foreach (ManagementObject b in
mo.GetRelated("Win32_DiskPartition"))
{
Console.WriteLine("{0}", b["Name"]);
foreach (ManagementBaseObject c in
b.GetRelated("Win32_LogicalDisk"))
Console.WriteLine("{0}", c["Name"]);
}
}
}
but it dint work..it throws an error "NOT FOUND" AT THIS LINE:
foreach (ManagementObject b in mo.GetRelated("Win32_DiskPartition"))
any idea y am i getting this exception?
thanx