How to get Drivelist including CD's & floopy drive info ..?

  • Thread starter Thread starter ¿ Mahesh Kumar
  • Start date Start date
You can do thiw with WMI (System.Management) if you want.
1. I want to list all the drives available in my system using C#..?

Enumerate Win32_LogicalDisk instances.

2. I want to check whether CD is inserted in CD-R or not.?

Enumerate Win32_CDROMDrive instances and check the MediaLoaded
property.



Mattias
 
Hi Mattias Sjögren..., I solved very simply with the following code written
by me with the guidance of MSDN.

//////////////////////////////////////// code to list the logical drives in
C# ////////////////////////

string[] dList = Directory.GetLogicalDrives();

for (int z = 0; z < dList.Length; z++)

{

DriveInfo drv = new DriveInfo(dList[z]);

if (drv.DriveType.ToString() == "CDRom")

{

MessageBox.Show(" Yes i got the directory..!!");

DirectoryInfo dInfo = new DirectoryInfo(drv.Name);

if (!dInfo.Exists)

throw new DirectoryNotFoundException("Directory does not exist....." + drv);

foreach (DirectoryInfo di in dInfo.GetDirectories())

{

MessageBox.Show(di.ToString());

loadFolderfiles(di.Name);

}

}

////////////////////////////////////////////////////////////////////////////
//////////////////////////////



Maheshkumar.R

www.snipurl.com/guac
 
Hi Butler,

String[] dirs = Directory.GetLogicalDrives(); // this line will get u all
the drives in your computer. Just iterate thru one by by and catch the
floppy drive presence or not..

foreach (string dir in dirs)

{

// if (dir == @"C:\")

// MessageBox.Show("Selected");

}


Maheshkumar.R
http://spaces.msn.com/members/cyberiafreak
 
Back
Top