473,767 Members | 1,578 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 \\.\PHYSICALDRI VE0 or
\\.\PHYSICALDRI VE1
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(Managemen tClass devs = new ManagementClass (
@"Win32_Diskdri ve"))
{
ManagementObjec tCollection moc = devs.GetInstanc es();
foreach(Managem entObject mo in moc)
{
Console.WriteLi ne(mo["DeviceId"]);
foreach (ManagementObje ct b in
mo.GetRelated(" Win32_DiskParti tion"))
{
Console.WriteLi ne("{0}", b["Name"]);
foreach (ManagementBase Object c in
b.GetRelated("W in32_LogicalDis k"))
Console.WriteLi ne("{0}", c["Name"]);
}
}
}

but it dint work..it throws an error "NOT FOUND" AT THIS LINE:
foreach (ManagementObje ct b in mo.GetRelated(" Win32_DiskParti tion"))

any idea y am i getting this exception?
thanx

Nov 17 '05 #1
4 25221

"sanjana" <su****@gmail.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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 \\.\PHYSICALDRI VE0 or
\\.\PHYSICALDRI VE1
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(Managemen tClass devs = new ManagementClass (
@"Win32_Diskdri ve"))
{
ManagementObjec tCollection moc = devs.GetInstanc es();
foreach(Managem entObject mo in moc)
{
Console.WriteLi ne(mo["DeviceId"]);
foreach (ManagementObje ct b in
mo.GetRelated(" Win32_DiskParti tion"))
{
Console.WriteLi ne("{0}", b["Name"]);
foreach (ManagementBase Object c in
b.GetRelated("W in32_LogicalDis k"))
Console.WriteLi ne("{0}", c["Name"]);
}
}
}

but it dint work..it throws an error "NOT FOUND" AT THIS LINE:
foreach (ManagementObje ct b in mo.GetRelated(" Win32_DiskParti tion"))

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.c om> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.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 \\.\PHYSICALDRI VE0 or
\\.\PHYSICALDRI VE1
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(Managemen tClass devs = new ManagementClass (
@"Win32_Diskdri ve"))
{
ManagementObjec tCollection moc = devs.GetInstanc es();
foreach(Managem entObject mo in moc)
{
Console.WriteLi ne(mo["DeviceId"]);
foreach (ManagementObje ct b in
mo.GetRelated(" Win32_DiskParti tion"))
{
Console.WriteLi ne("{0}", b["Name"]);
foreach (ManagementBase Object c in
b.GetRelated("W in32_LogicalDis k"))
Console.WriteLi ne("{0}", c["Name"]);
}
}
}

but it dint work..it throws an error "NOT FOUND" AT THIS LINE:
foreach (ManagementObje ct b in mo.GetRelated(" Win32_DiskParti tion"))

any idea y am i getting this exception?

Probably because the disk is not partitioned!

Willy.


Nov 17 '05 #3

"sanjana" <su****@gmail.c om> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.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.c om> wrote in message
news:11******** *************@g 43g2000cwa.goog legroups.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
1554
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 query As New System.Management.ManagementObjectSearcher("SELECT * From Win32_LogicalDisk") Dim queryCollection As System.Management.ManagementObjectCollection = query.Get() For Each mo As System.Management.ManagementObject In queryCollection
0
1764
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 query As New System.Management.ManagementObjectSearcher("SELECT * From Win32_LogicalDisk") Dim queryCollection As System.Management.ManagementObjectCollection = query.Get() For Each mo As System.Management.ManagementObject In queryCollection
0
3256
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 does not get a drive letter. Under my computer you only see the system partition. If you go to disk management you can see the data partition but does not have a drive letter. I am trying to write an application that would run after the system...
0
2500
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: StringCollection propNames = new StringCollection(); ManagementClass driveClass = new ManagementClass("Win32_DiskDrive"); PropertyDataCollection props = driveClass.Properties; foreach (PropertyData driveProperty in props) { propNames.Add(driveProperty.Name);
7
24165
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: StringCollection propNames = new StringCollection(); ManagementClass driveClass = new ManagementClass("Win32_DiskDrive"); PropertyDataCollection props = driveClass.Properties; foreach (PropertyData driveProperty in props) { propNames.Add(driveProperty.Name);
4
14491
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 giving J it should give me disk number 2. Any kind of help will be fuly appreciated Regards, Zeeshan
4
3474
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 = null; } This works as long as a drive letter is not FQFN. For instance,
1
1461
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 UncPath with drive Letter,is anybody there to help me to retrive the Drive letter from the UncPath Thanks in Advance Venkatramasamy SN
5
5918
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 can be clicked to open. Everything works well using an input=file then an onchange to update a hidden text field to capture the whole directory, but at the moment when saving a link, the uri (as such) is starting with the mapped drive letter on my...
0
9575
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9407
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8840
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5280
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5425
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3931
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2808
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.