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 }