下面的SAMPLE可能对你有所帮助。
procedure TForm1.Button1Click(Sender: TObject);
var
systeminfo: SYSTEM_INFO;
sector,byte,cluster,free: DWORD;
CDtype: UINT;
name: CHAR;
drvname: string;
volname,filesysname: PCHAR;
sno,maxl,fileflag: DWORD;
begin
Memo1.Lines.Clear();
//检测CD-ROM,是否有光盘
GetMem(volname, 255);
GetMem(filesysname, 100);
for name :='C' to 'Z' do
//循环检测A~Z
begin
drvname := name + ':';
CDtype := GetDriveType(PCHAR(@drvname[1]));
//获得磁盘类型
if (CDtype = DRIVE_CDROM) then
begin
Memo1.Lines.Add('您的光驱盘符为[' + drvname + ']');
volname^ := Chr(0);
filesysname^ := Chr(0);
if ( not (GetVolumeInformation(PCHAR(@drvname[1]), volname, 250, LPDWORD(@sno), LPDWORD(@maxl)^, LPDWORD(@fileflag)^, filesysname,100))) then
Memo1.Lines.Add(drvname + '驱中没有发现光盘') //如果返回值为假
else
//如果返回值为真
begin
Memo1.Lines.Add (drvname + '驱中光盘卷标为: [' + String(volname) + ']');
Memo1.Lines.Add (drvname + '驱中光盘序号为: [' + inttostr(sno) + ']');
end;
end;
end;
FreeMem(volname);
FreeMem(filesysname)
end;