C # obtain the drive letter of a Removable device

Source: Internet
Author: User
1   Using System;
2 Using System. Collections. Generic;
3 Using System. componentmodel;
4 Using System. Data;
5 Using System. drawing;
6 Using System. LINQ;
7 Using System. text;
8 Using System. Windows. forms;
9 Using Javesystem;
10 Using System. Management;
11 Using System. IO;
12 Using Microsoft. Win32;
13
14 Namespace Animationworldupdate
15 {
16 Public Partial Class Form_getremovabledeviceid: Form
17 {
18
19 Public List < String > Getremovabledeviceid ()
20 {
21 List < String > Deviceids = New List < String > ();
22 Managementobjectsearcher query = New Managementobjectsearcher ( " Select * From win32_logicaldisk " );
23 Managementobjectcollection querycollection = query. Get ();
24 Foreach (Managementobject Mo In Querycollection)
25 {
26 Switch ( Int . Parse (Mo [ " Drivetype " ]. Tostring ()))
27 {
28 Case ( Int ) Drivetype. removable: // The disk can be moved.
29 {
30 // MessageBox. Show ("removable disk ");
31 Deviceids. Add (Mo [ " DeviceID " ]. Tostring ());
32 Break ;
33 }
34 // Case (INT) drivetype. Fixed: // Local disk
35 // {
36 // // MessageBox. Show ("Local disk ");
37 // Break;
38 // }
39 // Case (INT) drivetype. CDROM: // Cd rom drives
40 // {
41 // MessageBox. Show ("cd rom drives ");
42 // Break;
43 // }
44 // Case (INT) drivetype. Network: // Network Driver
45 // {
46 // MessageBox. Show ("network drive ");
47 // Break;
48 // }
49 // Case (INT) drivetype. Ram:
50 // {
51 // MessageBox. Show ("the drive is a RAM disk ");
52 // Break;
53 // }
54 // Case (INT) drivetype. norootdirectory:
55 // {
56 // MessageBox. Show ("the drive has no root directory ");
57 // Break;
58 // }
59 Default : // Defalut to folder
60 {
61 // MessageBox. Show ("unknown drive type ");
62 Break ;
63 }
64 }
65
66 }
67 Return Deviceids;
68 }
69 }

 

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.