Shenzhen WeTERM Technology Co., Ltd
      进入中文版   ENGLISH
Products Category
Contact Us

Name: Jenny Shen
Tel: 0086-755-29127420(24lines)
Fax: 0086-755-22142733
E-mail: tina@digital555.com
Http: www.weterm.com
Skype: jenny52k66
Skype: jenny52k66

检测U盘代码

Author : Weterm Date : 12/25/2013 8:54:33 PM
检测U盘代码 C#代码
public
partial class Form1 : Form

    {

       
public const int WM_DEVICECHANGE = 0x219;

       
public const int DBT_DEVICEARRIVAL = 0x8000;

       
public const int DBT_CONFIGCHANGECANCELED = 0x0019;

       
public const int DBT_CONFIGCHANGED = 0x0018;

       
public const int DBT_CUSTOMEVENT = 0x8006;

       
public const int DBT_DEVICEQUERYREMOVE = 0x8001;

       
public const int DBT_DEVICEQUERYREMOVEFAILED = 0x8002;

       
public const int DBT_DEVICEREMOVECOMPLETE = 0x8004;

       
public const int DBT_DEVICEREMOVEPENDING = 0x8003;

       
public const int DBT_DEVICETYPESPECIFIC = 0x8005;

       
public const int DBT_DEVNODES_CHANGED = 0x0007;

       
public const int DBT_QUERYCHANGECONFIG = 0x0017;

       
public const int DBT_USERDEFINED = 0xFFFF;





       
public Form1()

        {

            InitializeComponent();

        }



       
protected override void WndProc(ref Message m)

        {

           
if (m.Msg == WM_DEVICECHANGE)

            {

                StringBuilder str
= new StringBuilder();

               
switch (m.WParam.ToInt32())

                {



                   
case DBT_DEVNODES_CHANGED:

                        DriveInfo[] drivers
= DriveInfo.GetDrives();

                       
foreach (DriveInfo info in drivers)

                        {

                           
if (info.DriveType == DriveType.Removable)

                            {

                                str.Append(
"盘符:" + info.Name);

                            }

                        }

                        MessageBox.Show(str.ToString());



                       
break;

                }

            }



           
base.WndProc(ref m);

        }

    }