Subject: CD-ROM device name 85. ***** Q: How do I get the character device name of the (first) CD-ROM? A: First the code for a quick and dirty method to find the character device name function MSCDEXFN : string; var s : string; f : text; i : byte; fmSave : byte; begin mscdexfn := ''; { To indicate not found } fmSave := FileMode; { Store the original file mode } FileMode := 0; { Also if read-only } Assign (f, 'c:\autoexec.bat'); { Browse the AUTOEXEC.BAT } {$I-} Reset (f); {$I+} if IOResult <> 0 then exit; { AUTOEXEC.BAT not found } while not eof(f) do begin { Line by line } readln (f, s); for i := 1 to Length(s) do s[i] := Upcase(s[i]); if Pos('MSCDEX', s) > 0 then begin { Is this the line } if Pos ('REM', s) = 1 then continue; { Skip rem lines } Close (f); FileMode := fmSave; { Restore the original mode } i := Pos('/D:', s); { Look for the switch } if i = 0 then exit; { Nah! } i := i + 3; { Where the name should start } if i > Length(s) then exit; { Nothing there! } s := Copy (s, i, 255); { Rest of the line after /D: } mscdexfn := s; i := Pos (' ', s); if i = 0 then exit; mscdexfn := Copy (s, 1, i-1); exit; { Don't close twice } end; {if} end; {while} Close (f); FileMode := fmSave; { Restore the original mode } end; (* mscdexfn *) A2: There is more general and orthodox solution to finding the character device name for the (first)m CD-ROM. This was kindly provided to me by Chris Rankin (rankin@shfax1.shef.ac.uk). uses Dos; function GetCDROMDevice : string; const driver_name_len = 8; type sig = array[1..6] of char; siglet = array[1..4] of char; signum = array[1..2] of char; drvname = array[1..driver_name_len] of char; driverstr = string[driver_name_len]; type PCDROMDriver = ^TCDROMDriver; TCDROMDriver = record NextDriver: PCDROMDriver; DeviceAttr: word; StrategyEntryPoint: word; INTEntryPoint: word; DeviceName: drvname; Reserved: word; DriveLetter: byte; Units: byte; case byte of 0: (SigLetters: siglet; SigNumbers: signum); 1: (Signature: sig) end; TDriveEntry = record SubUnit: byte; Driver: PCDROMDriver end; var DeviceList: array[1..26] of TDriveEntry; Regs: registers; Name: driverstr; begin with Regs do begin ax := $1500; bx := 0; intr($2f,Regs); (* Ask for number of CD-ROM drives. *) if bx = 0 then (* If none, then exit. *) begin Name[0] := #0; GetCDROMDevice := Name; exit end; ax := $1501; (* Put information about each CD-ROM *) es := seg(DeviceList); (* into DeviceList[]. *) bx := ofs(DeviceList); intr($2f,Regs) end; (* Below: Name of first CD-ROM driver *) Name := DeviceList[1].Driver^.DeviceName; while Name[length(Name)] = ' ' do (* Strip off trailing blanks.. *) dec(Name[0]); GetCDROMDevice := Name end; --------------------------------------------------------------------