C # get all the drive letter of the local computer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.