获得盘符:
procedure TForm1.Button1Click(Sender: TObject);
var
ch:char;
temp:string;
Hard: array of char;
i:integer;
begin
ch:='c';
i:=1;
setlength(Hard,i);
while GetDriveType(pchar(string(temp)))<>DRIVE_CDROM do
begin
Hard[i-1]:=ch;
i:=i+1;
setlength(Hard,i);
ch:=chr(integer(ch)+1);
temp:=ch+':\';
Edit1.Text:=Edit1.Text+Hard[i-2]+',';
end;
end;
type
MIDPtr = ^MIDRec;
MIDRec = Record
InfoLevel: word;
SerialNum: LongInt;
VolLabel: Packed Array [0..10] of Char;
FileSysType: Packed Array [0..7] of Char;
end;
function GetDriveSerialNum(MID: MIDPtr; drive: Word): Boolean; assembler;
asm
push DS { Just for safety, I dont think its really needed }
mov ax,440Dh { Function Get Media ID }
mov bx,drive { drive no (0-Default, 1-A ...) }
mov cx,0866h { category and minor code }
lds dx,MID { Load pointeraddr. }
call DOS3Call { Supposed to be faster than INT 21H }
jc @@err
mov al,1 { No carry so return TRUE }
jmp @@ok
@@err:
mov al,0 { Carry set so return FALSE }
@@ok:
pop DS { Restore DS, were not supposed to change it }
end;
procedure TForm1.NrBtnClick(Sender: TObject);
var
Info: MIDRec;
begin
Info.InfoLevel:=0; { Information Level }
If GetDriveSerialNum(@Info,0) then { Do something with it... }
ListBox.Items.Add(IntToStr(Info.SerialNum)+' '+Info.VolLabel);
end;