如何确定一个驱动器的类型是光驱,是闪存,或是手机的插进电脑? ( 积分: 100 )

  • 主题发起人 主题发起人 wqhatnet
  • 开始时间 开始时间
W

wqhatnet

Unregistered / Unconfirmed
GUEST, unregistred user!
如何确定一个驱动器的类型是光驱,是闪存,或是手机的插进电脑产生的盘符,或者它是正常的驱动器?
 
function GetDrvType(const ADrive: PChar): string;
var
dval: DWORD;
begin
dval := GetDriveType(ADrive);
case dval of
0: Result := 'The drive type cannot be determined.';
1: Result := 'The root directory does not exist.';
DRIVE_REMOVABLE: Result := 'The drive can be removed from the drive.';
DRIVE_FIXED: Result := 'The disk cannot be removed from the drive.';
DRIVE_REMOTE: Result := 'The drive is a remote (network) drive.';
DRIVE_CDROM: Result := 'The drive is a CD-ROM drive.';
DRIVE_RAMDISK: Result := 'The drive is a RAM disk.';
end;
end;

UINT GetDriveType(LPCTSTR lpRootPathName);
Parameters
lpRootPathName
Points to a null-terminated string that specifies the root directory of the disk to return information about. If lpRootPathName is NULL, the function uses the root of the current directory.
Return Values
The return value specifies the type of drive. It can be one of the following values:
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.
 
现成的例子:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
//检测结果
Result:Integer;
//驱动器根目录
Driver:String;
begin
Driver:=Edit1.text;
//检测驱动器类型
Result:=GetDriveType(pchar(Driver));
Case Result of
Drive_Removable:Memo1.Lines.Add(Edit1.text+'为可移动驱动器');
Drive_Fixed:Memo1.Lines.Add(Edit1.text+'不可移动驱动器');
Drive_Remote:Memo1.Lines.Add(Edit1.text+'网络驱动器');
Drive_CDROM:Memo1.Lines.Add(Edit1.text+'CD-ROM驱动器');
Drive_RamDisk:Memo1.Lines.Add(Edit1.text+'虚拟驱动器');
Else Memo1.Lines.Add(Edit1.text+'驱动器符号无效');
end;
end;


end.
 
如何获取所有的驱动器盘符?
 
我都帮你做好了,你多给点分:
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;

type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
var
d1: Char;
s: String;
begin
for d1:='A' to 'Z' do
begin
s := d1 + ':';
case GetDriveType(PChar(s)) of
0: s := s + '驱动器类型不能判断.';
1: begin s := s + '根目录不存在.';CONTINUE;end;
DRIVE_REMOVABLE: s := s + '为可移动驱动器.';
DRIVE_FIXED: s := s + '不可移动驱动器.';
DRIVE_REMOTE: s := s + '是网络驱动器.';
DRIVE_CDROM: s := s + '是CD-ROM驱动器';
DRIVE_RAMDISK: s := s + '虚拟驱动器.';

else
// s := s + '驱动器符号无效';
end;
if Length(s)>3 then
Memo1.Lines.Add(s);
end;
end;

end.
 
多人接受答案了。
 
后退
顶部