473,396 Members | 1,884 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

get drive letter( Win32_Diskdrive)

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

Nov 17 '05 #1
4 25077

"sanjana" <su****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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?

Probably because the disk is not partitioned!

Willy.
Nov 17 '05 #2
hi
ya..its working fine..now i am getting the drive letter from the code
thanx...

just a small doubt i have
i get the drive letter whenever i insert the media card in the
particular drive..cf card or sd card..in the drive,..

but i dont get the drive letter when i remove the media card(sd/cf
card)
when i remove the card it gives me /.//physicaldrive1..but doesent map
to the drive letter say (E:)

any reasons for this..?

i had done some cd insertion /removal event detection ..where i used to
get the drive letetr..even if the cd was removed and inserted..
then y does it not work similarly for media cards..

thanx for ur time and advice..


Willy Denoyette [MVP] wrote:
"sanjana" <su****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
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?

Probably because the disk is not partitioned!

Willy.


Nov 17 '05 #3

"sanjana" <su****@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
hi
ya..its working fine..now i am getting the drive letter from the code
thanx...

just a small doubt i have
i get the drive letter whenever i insert the media card in the
particular drive..cf card or sd card..in the drive,..

but i dont get the drive letter when i remove the media card(sd/cf
card)
when i remove the card it gives me /.//physicaldrive1..but doesent map
to the drive letter say (E:)

any reasons for this..?

i had done some cd insertion /removal event detection ..where i used to
get the drive letetr..even if the cd was removed and inserted..
then y does it not work similarly for media cards..

thanx for ur time and advice..

The drive letter is asssigned when the card is present and formatted, that
is when a volume is mounted.
CD's are assigned fixed driver letters by the OS even when no CD is present,
memory cards are not.
Willy.

Nov 17 '05 #4
hi
ok
got it
thanx

Willy Denoyette [MVP] wrote:
"sanjana" <su****@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
hi
ya..its working fine..now i am getting the drive letter from the code
thanx...

just a small doubt i have
i get the drive letter whenever i insert the media card in the
particular drive..cf card or sd card..in the drive,..

but i dont get the drive letter when i remove the media card(sd/cf
card)
when i remove the card it gives me /.//physicaldrive1..but doesent map
to the drive letter say (E:)

any reasons for this..?

i had done some cd insertion /removal event detection ..where i used to
get the drive letetr..even if the cd was removed and inserted..
then y does it not work similarly for media cards..

thanx for ur time and advice..

The drive letter is asssigned when the card is present and formatted, that
is when a volume is mounted.
CD's are assigned fixed driver letters by the OS even when no CD is present,
memory cards are not.
Willy.


Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Ben Reese | last post by:
Kind people on this discussion group have previously helped me to dynamically identify CD rom drives etc at runtime using objects in System.management +++++++++++++++++++++++++++++++++++++++ Dim...
0
by: Ben Reese | last post by:
Kind people on this discussion group have previously helped me to dynamically identify CD rom drives etc at runtime using objects in System.management +++++++++++++++++++++++++++++++++++++++ Dim...
0
by: BK Drake | last post by:
I am trying to assign a drive letter to a hidden partition. I have a hard drive that has 2 paritions - a system and a data partition. When I retore with an image the system drive the data drive...
0
by: john doe | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
7
by: jimdscudder | last post by:
How can I use WMI or a WqlObjectQuery to find the hard drive letter of the physical drive location index. For example the following code will give me the physical drive location:...
4
by: Zeeshan | last post by:
hi, i want to get the hard drive number for example if if have drive letter C it should tell me Disk number as 1 and suppose if i have another hard disk attach to my system having letter J, the by...
4
by: Jim Carlock | last post by:
function CreateMyDataBaseFile($FQFN, $UID, $PW) { $db = "sqlite:" . $FQFN; $sql = "CREATE TABLE Customers(name1 TEXT, name2 TEXT);"; $dbh = new PDO($db, $UID, $PW); $dbh->exec($sql); $dbh =...
1
by: VEnkatramasamy | last post by:
Hi to Every one One of my prgram expects drive letter for validation purpose(which can't be negotiated),while hadling the mappeddrives no problem with any OS except Windows vista, it returns the...
5
by: BigM | last post by:
Hi Guys, I am working up a little 'documents' section to an app of mine, where people can add links to docs on various share drives in our LAN, and they are displayed along with other details and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.