Getting the serial number of the CDROM
   


Use this function to determine the serial number of the CDROM. Will only return a result if there is a CDROM in the drive.

uses MMSystem, MPlayer;

function CDSerialNumber(CD: Char): string;
{ func to return the serial number on the CD. Works on audio & data CDs. }
var
  mp : TMediaPlayer;
  msp : TMCI_INFO_PARMS;
  MediaString : array[0..255] of char;
  ret : longint;
begin
  mp := TMediaPlayer.Create(nil);
  try
    mp.Visible := False;
    mp.Parent := Application.MainForm;
    mp.Shareable := True;
    mp.DeviceType := dtCDAudio;
    mp.FileName := CD + ':';
    mp.Open;
    Application.ProcessMessages;
    FillChar(MediaString, SizeOf(MediaString), #0);
    FillChar(msp, SizeOf(msp), #0);
    msp.lpstrReturn := @MediaString;
    msp.dwRetSize := 255;
    ret := mciSendCommand(Mp.DeviceId,
                          MCI_INFO,
                          MCI_INFO_MEDIA_IDENTITY,
                          longint(@msp));
    if Ret <> 0 then
      begin
        MciGetErrorString(ret, @MediaString, SizeOf(MediaString));
        Result := StrPas(MediaString);
      end
    else
      Result := StrPas(MediaString);
    mp.Close;
    Application.ProcessMessages;
  finally
    mp.free;
  end;
end;


Blue Orb Software

[email protected]