C # get all the drive letter of the local computer
Speak not much, direct serving:
Public list<string> Getremovabledeviceid ()
{
list<string> deviceids = new list<string> ();
ManagementObjectSearcher query = new ManagementObjectSearcher ("SELECT * from Win32_LogicalDisk");
Managementobjectcollection querycollection = query. Get ();
foreach (ManagementObject mo in querycollection)
{
switch (int. Parse (mo["DriveType"). ToString ()))
{
case (int) Drivetype.removable://Can move disk
{
MessageBox.Show ("removable disk");
Deviceids.add (mo["DeviceID"). ToString ());
Break
}
case (int) drivetype.fixed://Local Disk
{
MessageBox.Show ("Local Disk");
Deviceids.add (mo["DeviceID"). ToString ());
Break
}
case (int) Drivetype.cdrom://CD ROM drives
{
MessageBox.Show ("CD ROM drives");
Break
}
case (int) Drivetype.network://Network Driver
{
MessageBox.Show ("network Drive");
Break
}
case (int) Drivetype.ram:
{
MessageBox.Show ("Drive is a RAM disk");
Break
}
case (int) Drivetype.norootdirectory:
{
MessageBox.Show ("Drive without root directory");
Break
}
Default://defalut to Folder
{
MessageBox.Show ("Drive type Unknown");
Break
}
}
}
return deviceids;
}
C # get all the drive letter of the local computer