コード例 #1
0
 void t_Elapsed(object sender, ElapsedEventArgs e)
 {
     DriveInfo[] drives = DriveInfo.GetDrives();
     foreach (DriveInfo d in drives)
     {
         if (d.DriveType == DriveType.Removable)
         {
             Console.WriteLine(d.Name);
             Ulog.EjectUsb eju    = new Ulog.EjectUsb(d.Name);
             bool          result = eju.Eject();
             if (result == true)
             {
                 MessageBox.Show("振兴妙妙屋开启!!!");
             }
         }
     }
 }
コード例 #2
0
        public const int DBT_USERDEFINED             = 0xFFFF; //此消息的含义是用户定义的
        #endregion



        #region 检测u盘
        protected override void WndProc(ref Message m)
        {
            try
            {
                if (m.Msg == WM_DEVICECHANGE)
                {
                    switch (m.WParam.ToInt32())
                    {
                    case WM_DEVICECHANGE:
                        DriveInfo[] drives = DriveInfo.GetDrives();
                        foreach (DriveInfo d in drives)
                        {
                            if (d.DriveType == DriveType.Removable)
                            {
                                Console.WriteLine(d.Name);
                                Ulog.EjectUsb eju    = new Ulog.EjectUsb(d.Name);
                                bool          result = eju.Eject();
                                if (result == true)
                                {
                                    MessageBox.Show("振兴妙妙屋开启!!!");
                                }
                            }
                        }
                        break;

                    case DBT_DEVICEARRIVAL:    //U盘插入

                        break;

                    case DBT_CONFIGCHANGECANCELED:
                        break;

                    case DBT_CONFIGCHANGED:
                        break;

                    case DBT_CUSTOMEVENT:
                        break;

                    case DBT_DEVICEQUERYREMOVE:
                        break;

                    case DBT_DEVICEQUERYREMOVEFAILED:
                        break;

                    case DBT_DEVICEREMOVECOMPLETE:     //U盘卸载

                        break;

                    case DBT_DEVICEREMOVEPENDING:
                        break;

                    case DBT_DEVICETYPESPECIFIC:
                        break;

                    case DBT_DEVNODES_CHANGED:
                        break;

                    case DBT_QUERYCHANGECONFIG:
                        break;

                    case DBT_USERDEFINED:
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            base.WndProc(ref m);
        }