关键是盘符的获取
有些U盘 如装有U3 等U盘辅助工具的, 会产生一个虚拟盘,造成混乱.

解决方案 »

  1.   

    获取可以用消息WM_DEVICECHANGE,设备发生改变
    至于盘符,写代码找一下吧,并不难
      

  2.   

    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure WMDeviceChange(var Msg: TMessage); message WM_DEVICECHANGE;
      end;var
      Form1: TForm1;implementation{$R *.dfm}
    procedure TForm1.WMDeviceChange(var Msg: TMessage);  
    begin  
       Case Msg.WParam of
         32768:
          begin
           caption :='U盘插入';
           MessageBox(0,'注意!U盘已插入!!!','AutoCopy Information',MB_ICONASTERISK and MB_ICONINFORMATION);
          end;
         32772:
          begin
           caption :='U盘拔出';
           MessageBox(0,'注意!U盘已取走!!!','AutoCopy Information',MB_ICONASTERISK and MB_ICONINFORMATION);
          end;
       end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    //看哪个盘是U盘
    var
        buf:array [0..MAX_PATH-1] of char;  
        m_Result:Integer;  
        i:Integer;  
        str_temp:string;  
    begin  
    m_Result:=GetLogicalDriveStrings(MAX_PATH,buf);
    for i:=0 to (m_Result div 4) do  
    begin  
            str_temp:=string(buf[i*4]+buf[i*4+1]+buf[i*4+2]);  
             if GetDriveType(pchar(str_temp)) = DRIVE_REMOVABLE then  
             begin  
                ShowMessage(str_temp+'盘 为U盘');
            end;  
    end;
    end;end.