473,408 Members | 2,477 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,408 software developers and data experts.

Finding the CD drives on a system

Is there a way to detect how many, and what drive letters the CD/DVD drives
on a system are?

Any help is greatly appreciated.
Nov 17 '05 #1
5 2813
mdb
"Greg Smith" <gj*@umn.edu> wrote in
news:OY**************@TK2MSFTNGP10.phx.gbl:
Is there a way to detect how many, and what drive letters the CD/DVD
drives on a system are?


You can use Environment.GetLogicalDrives to enumerate them, and
kernel32.dll's GetDriveType to figure out what it is.

using System;
using System.Collections;
using System.Runtime.InteropServices;

public class MyClass
{
[DllImport("kernel32.dll")]
public static extern DriveType GetDriveType( string lpRootPathName );

public enum DriveType : uint
{
DRIVE_UNKNOWN = 0,
DRIVE_NO_ROOT_DIR = 1,
DRIVE_REMOVABLE = 2,
DRIVE_FIXED = 3,
DRIVE_REMOTE = 4,
DRIVE_CDROM = 5,
DRIVE_RAMDISK = 6
}

public static void Main()
{
string[] x = Environment.GetLogicalDrives();
foreach(string y in x)
{
DriveType t = GetDriveType(y);
Console.WriteLine(y + " - " + t.ToString());
}
Console.ReadLine();
}
}

--
-mdb
Nov 17 '05 #2
I think the best way doing this, is the following code snippet

foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
Console.WriteLine("{0}\t{1}", drive.Name, drive.DriveType);
HTH
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

"Greg Smith" <gj*@umn.edu> wrote in message
news:OY**************@TK2MSFTNGP10.phx.gbl...
Is there a way to detect how many, and what drive letters the CD/DVD
drives on a system are?

Any help is greatly appreciated.

Nov 17 '05 #3
This class in new in v2.0 of the framework.

Willy.

"Yunus Emre ALPÖZEN [MCSD.NET]" <ye***@msakademik.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I think the best way doing this, is the following code snippet

foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
Console.WriteLine("{0}\t{1}", drive.Name, drive.DriveType);
HTH
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

"Greg Smith" <gj*@umn.edu> wrote in message
news:OY**************@TK2MSFTNGP10.phx.gbl...
Is there a way to detect how many, and what drive letters the CD/DVD
drives on a system are?

Any help is greatly appreciated.


Nov 17 '05 #4
mdb
"Yunus Emre ALPÖZEN [MCSD.NET]" <ye***@msakademik.net> wrote in news:
#i**************@TK2MSFTNGP14.phx.gbl:
foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
Console.WriteLine("{0}\t{1}", drive.Name, drive.DriveType);


System.IO.DriveInfo doesn't compile for me... is this .NET 2.0?

--
-mdb
Nov 17 '05 #5
Yes... For Framework1.1 u must write a code like as u pointed out. Or u can
use something like this;
http://groups.msn.com/windowsscript/...=2&sortstring=
--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

"mdb" <m_b_r_a_y@c_t_i_u_s_a__d0t__com> wrote in message
news:Xn****************************@207.46.248.16. ..
"Yunus Emre ALPÖZEN [MCSD.NET]" <ye***@msakademik.net> wrote in news:
#i**************@TK2MSFTNGP14.phx.gbl:
foreach (System.IO.DriveInfo drive in System.IO.DriveInfo.GetDrives())
Console.WriteLine("{0}\t{1}", drive.Name, drive.DriveType);


System.IO.DriveInfo doesn't compile for me... is this .NET 2.0?

--
-mdb

Nov 17 '05 #6

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

Similar topics

3
by: Ned Hart | last post by:
I'm formatting my mirrored drives and installing a third drive for raid 5 to add more space. I have backup exec. Can anyone tell me the best way to backup SQL so I can be sure it will restore...
2
by: lastusernameleft | last post by:
Is there a .NET method for doing this? I haven't found anything else that works. Thanks
36
by: Ron Johnson | last post by:
http://hardware.devchannel.org/hardwarechannel/03/10/20/1953249.shtml?tid=20&tid=38&tid=49 -- ----------------------------------------------------------------- Ron Johnson, Jr....
3
by: Simon Harvey | last post by:
Hi there everyone, I'm hoping that someone could point me in the direction of the necessary classes required to determine information on a computers filesystem. In particular, how can enumerate...
3
by: Flix | last post by:
I need to detect the root directories of the installed hard disks (es: C:, D:, E:, etc.). I'm not interested in cd drives. I know that there is a way (a bit slow, if I remeber) to retrive all the...
2
by: Pradeep Sundaram(MSFT) | last post by:
Hello, I want to enumerate all the Drives on the web server using ASP.NET (C#) Writing code like this works when i use local host but when i try to access it from another machine it does not show...
0
by: Andreas Reisenhofer | last post by:
Hallo VB.NET's We are trying to use FindFirstChangeNotification under VB6 and FileSystemWatcher with vb.net and got no success on drives mapped with InterDriveClient (5.0,7.11) on a NetApp...
1
by: DBC User | last post by:
I have a program in the network location, which when running, it needs to find out what are all the drives available in the PC. I have the following code in my program using (ManagementClass...
2
by: HardySpicer | last post by:
Some pcs have only the c drive whilst others like mine have c,d,e,f and z! How do I detect this automatically if I want to search all drives in a pc? I also want to ignore the DVD and floppy of...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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,...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.