注意不能用 GetDriveType 判断 , 因为 GetDriveType 对某些U盘 判断为 固定的磁盘!!!!!!!!!
请给出详细 的代码 谢谢!!!!!!!!!!!!!!!!!!!!!

解决方案 »

  1.   

    除非分区固定 C\D\E\F...为硬盘分区, 其他的所有都是usb盘符,要不然没有什么办法
      

  2.   

    如果你的程序能够在插入U盘之前启动的话,接收USB插入的消息BDT_DEVICEARRIVAL = $8000;然后扫描磁盘是否变化,这样应当可以吧?(不排除你插USB设备的同时也有硬盘接入,那可就不行了)
        以前看过一个类似设备管理器的程序源代码,一时找不到在那里了。那个程序应当可以解决的。
      

  3.   

    etomahawk(一意孤行) 你 的办法不行 啊 , 如果在 没有运行 程序前 已经 插入了 , 这样就判断不了 , 我听说可以判断 总线 类型的,但不知道怎样实现, 有谁知道呢???????????????
      

  4.   

    可以通过SetupAPI配合Volume查询命令获得~~
      

  5.   

    http://cache.web745.com/5308/26965.html
      

  6.   

    ly_liuyang 你能不能给出详细的代码??
      

  7.   

    楼主:我给你的那个网址,就是详细代码。
    http://cache.web745.com/5308/26965.html
      

  8.   

    TO : dBASEIII 你的 程序上用  GetDriveType  判断 的!!
    不能用 GetDriveType 判断 , 因为 GetDriveType 对某些U盘 判断为 固定的磁盘
      

  9.   

    你脑子有毛病吧??问这样的问题!!!?????象你说得,把U盘插上了,然后打开程序,让程序去看该盘是不是U盘??  那我告诉你:打死他也不可能认出来!!! 打死你也写不出这样的程序!!!应该是程序时刻监测是否有事件发生吧?? 因为插入U盘的时候,系统会收到特定的事件,那么你的程序也能够收到特定的事件。也就是说只有在插拔U盘的时候,才可能判断出来是否有U盘插入.凑合的办法:
    另外因为 GetDriveType 对某些U盘 判断为 固定的磁盘,你要换个角度看问题,不是这个函数不行,是别人的U盘不兼容,让他去死吧,换U盘!!!
      

  10.   

    把U盘插上了,然后打开程序,让程序去看该盘是不是USB移动盘,是一定可行的!!!
    至于区分USB闪存盘和USB移动硬盘,就无能为力~具体代码,需要有偿提供~~
      

  11.   

    应该可以的,如通用税务数据采集软件就是用DELPHI开发的,实现了计算机上是否有U盘,但不知道是如何实现的,不好意思
      

  12.   

    用WMI肯定可以(WMI可得到系统所有信息),以下为例程(当然你可以通过Win32_USBControllerDevice或其它项目来判):
    unit wmi;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls;type
      TForm1 = class(TForm)
        Button1: TButton;
        Memo1: TMemo;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}uses
    ActiveX, WbemScripting_TLB;
    function ADsEnumerateNext(pEnumVariant: IEnumVARIANT; cElements: ULONG;
      var pvar: OleVARIANT; var pcElementsFetched: ULONG): HRESULT; safecall; external 'activeds.dll';procedure DumpWMI_Process(Process: SWBemObject);
    var
      Enum: IEnumVARIANT;
      varArr: OleVariant;
      lNumElements: ULong;
      SProp: ISWbemProperty;
      Prop: OleVariant;
      PropName: string;
      PropType: string;
      PropValue: string;
    begin
      Form1.Memo1.Lines.Add('+ WMI Path: ' + Process.Path_.Path);
      Enum := Process.Properties_._NewEnum as IEnumVariant;
      while (Succeeded(ADsEnumerateNext(Enum, 1, VarArr, lNumElements))) and
        (lNumElements > 0) do
      begin
        if Succeeded(IDispatch(varArr).QueryInterface(SWBemProperty, SProp)) and
          Assigned(SProp) then
        begin
          try
            PropName  := SProp.Name;
            Prop := SProp.Get_Value;
            PropType := inttostr((VarType(Prop)));
            PropValue := VarToStr(Prop);
            Form1.Memo1.Lines.Add('  + ' + PropName + '[' + PropType + '] = ' + PropValue);
          except
            on E: Exception do
            begin
              // WriteLn(ErrOutput, PropName, ': ', E.Message);
            end;
          end;
        end;
      end;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      Server: string;
      Enum: IEnumVARIANT;
      varArr: OleVariant;
      lNumElements: ULong;
      AName: array[0..255] of Char;
      ASize: DWORD;
    begin
      if (ParamCount = 0) then
      begin
        Server := '';
        ASize  := SizeOf(AName) - 1;
        if GetComputerName(@AName, ASize) then Server := AName;
      end
      else
      begin
        Server := ParamStr(1);
      end;
      try
        Memo1.Lines.BeginUpdate;
        Enum := CoSWbemLocator.Create.ConnectServer(Server, 'root\cimv2', '',
          '', '', '', 0, nil).ExecQuery('Select  InterfaceType from Win32_DiskDrive', 'WQL',
          wbemFlagBidirectional, nil)._NewEnum as IEnumVariant;
        while (Succeeded(ADsEnumerateNext(Enum, 1, varArr, lNumElements))) and
          (lNumElements > 0) do
        begin
          DumpWMI_Process(IUnknown(varArr) as SWBemObject);
        end;
      finally
        Memo1.Lines.EndUpdate;
      end;
    end;
     ////其中,WbemScripting_TLB.pas可从   
      ///http://www.truth4all.org/WbemScripting_TLB.pas   
      ///下载   
        
    end.
      

  13.   

    keiy()  你的方法不行啊 !!!
      

  14.   


    keiy()  你的方法 只是返回 ,下面的信息, 不能判断 那个盘是 USB 接口的磁盘!!!
    + WMI Path: \\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE1"
      + DeviceID[8] = \\.\PHYSICALDRIVE1
      + InterfaceType[8] = IDE
    + WMI Path: \\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0"
      + DeviceID[8] = \\.\PHYSICALDRIVE0
      + InterfaceType[8] = IDE
    + WMI Path: \\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE2"
      + DeviceID[8] = \\.\PHYSICALDRIVE2
      + InterfaceType[8] = USB
      

  15.   

    但靠 InterfaceType[8] = USB  , 不能 判断 哪里个 盘符是 USB磁盘 !!!!
      

  16.   

    呵呵....那么你知道下面的信息是如何给出的吗+ WMI Path: \\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE1"
      + DeviceID[8] = \\.\PHYSICALDRIVE1
      + InterfaceType[8] = IDE
    + WMI Path: \\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE0"
      + DeviceID[8] = \\.\PHYSICALDRIVE0
      + InterfaceType[8] = IDE
    + WMI Path: \\LITONE-MSJF7C5U\root\cimv2:Win32_DiskDrive.DeviceID="\\\\.\\PHYSICALDRIVE2"
      + DeviceID[8] = \\.\PHYSICALDRIVE2
      + InterfaceType[8] = USB呵,有意思。谁让你靠上面的字串来判断呢?
      

  17.   

    dBASEIII 你有什么办法判断????
      

  18.   

    如果是移动硬盘接USB,只怕是不行。
      

  19.   

    往上写点东西,看速度,看usb端口有没数据传输,呵呵,随便说说
      

  20.   

    disksize:=0;
      for i:=99 to 122 do      // 'c'-'z';
        begin
          drive:=pchar(chr(i)+':\');
          x:=GetDriveType(drive);
          if x=3 then              //3:代表介质是硬盘.
             begin
               GetDiskFreeSpaceEx(drive,userFreeBytes,totalBytes,@freeBytes);
               k:=1000000000;
               disksize:=totalBytes div k;
               ListItem:=ListView1.Items.Add;
               ListItem.Caption:=UpperCase(chr(i))+' 驱动器';
               ListItem.SubItems.Add(Formatfloat('###,##0',disksize)+'G');
             end;
          if x=2 then      //removable
             begin
               GetDiskFreeSpaceEx(drive,userFreeBytes,totalBytes,@freeBytes);
               disksize:=totalBytes div 1048576;           ListItem:=ListView1.Items.add;
               ListItem.Caption:=UpperCase(chr(i))+' 可移动磁盘';
               ListItem.SubItems.Add(inttostr(disksize)+'M');
             end;
        end;