怎样在系统中检测到USB flash disk,并获得它的根目录(盘符)????

解决方案 »

  1.   

    for DriveNum := 0 to 25 do
      begin
        if not (DriveNum in DriveBits) then Continue;
        DriveChar := Char(DriveNum + Ord('a'));
        DriveType := TDriveType(GetDriveType(PChar(DriveChar + ':\')));
        if TextCase = tcUpperCase then
          DriveChar := Upcase(DriveChar);    case DriveType of
          dtFloppy:   Items.AddObject(DriveChar + ':', FloppyBMP);
          dtFixed:    AddDrive(VolumeID(DriveChar), FixedBMP);
          dtNetwork:  AddDrive(NetworkVolume(DriveChar), NetworkBMP);
          dtCDROM:    AddDrive(VolumeID(DriveChar), CDROMBMP);
          dtRAM:      AddDrive(VolumeID(DriveChar), RAMBMP);
        end;
      end;
      

  2.   

    UINT GetDriveType(    LPCTSTR lpRootPathName  // address of root path 
       );Value Meaning
    0 The drive type cannot be determined.
    1 The root directory does not exist.
    DRIVE_REMOVABLE The drive can be removed from the drive.
    DRIVE_FIXED The disk cannot be removed from the drive.
    DRIVE_REMOTE The drive is a remote (network) drive.
    DRIVE_CDROM The drive is a CD-ROM drive.
    DRIVE_RAMDISK The drive is a RAM disk.//sample:可以用消息,给你贴一段zswang兄的://思路是监测驱动器的改变~~
    //插来插去,测试了一下,得到的数值~~type
      TForm1 = class(TForm)
        Memo1: TMemo;
      private
        { Private declarations }
        procedure WMDEVICECHANGE(var Msg: TMessage); message WM_DEVICECHANGE; //驱动器改变
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.WMDEVICECHANGE(var Msg: TMessage);
    begin
      inherited;
      case Msg.WParam of
        32772: Caption := '关闭';
        32768: Caption := '就绪';
      end;
    end;