1、用GetLogicalDrives() 或 GetLogicalDriveStrings() 遍历驱动器<br>2、用GetDriveType() 检测每个驱动器的属性,如果是 DRIVE_CDROM 则表示是光驱。<br><br>有这样的现成函数处理。大致的处理如下:<br>>> 第一种:用GetLogicalDrives()<br>var<br> dwDrives: Longword;<br> dwMask: LongWord;<br> chDrive: char;<br>begin<br> dwDrives = GetLogicalDrives();<br><br> dwMask = $00000001;<br> chDrive = 'B';<br> while loop_count < 27 (windows 最大接受盘符)<br> if dwDrives and drMask <> 0(有效盘符) then<br> begin<br> chDrive = Chr(Ord(chDrive) + 1); (盘符从C开始,顺序递增盘符)<br> check_drive_type;<br> if DRIVE_CDROM then<br> add your process code here;<br> endif<br> dwMask shr 1;<br> endwhile<br>end;<br><br>>> 第二种:用GetLogicalDriveStrings()<br>const<br> MAX_DRIVE_BUFFER_SIZE = 128;<br>var<br> Drives: PChar;<br>begin<br> AllocMem(Drives, MAX_DRIVE_BUFFER_SIZE);<br> GetLogicalDriveStrings(Drives, MAX_DRIVE_BUFFER_SIZE);<br><br> //到此可以得到c:/<null>d:/<null><null>的串<br> while not EOS(EOS 为最后连续两个字符都为 #0#0!)<br> check_drive_type;<br> if DRIVE_CDROM then<br> add your process code here;<br><br> //扫描时必须判断到连续两个Null才算终结。<br> Inc(Drives);<br> if Drives^ = #0 then Inc(Drives);<br> EOS = Drives^ = #0;<br> endwhile<br>end;<br><br>注:由于NT可以自己分配盘符(不一定要C, D...依次排列),所以用第二种方法要更可靠些。