procedure ShieldCDs;<br> function IsCDROM(DriveChar: Char): Boolean;<br> begin<br> Result := GetDriveType(PChar(DriveChar + ':/')) = DRIVE_CDROM;<br> end;<br>const<br> _PATH = '/Software/Microsoft/Windows/CurrentVersion/Policies/Explorer';<br>var<br> I, T: Integer;<br> Buffer, Mask: DWORD;<br> R: TRegistry;<br>begin<br> Mask := 0;<br> for I := 0 to 25 do<br> if IsCDROM(Char(I + Ord('A'))) then Mask := Mask + 1 shl I;<br> R := TRegistry.Create;<br> R.Rootkey := HKEY_CURRENT_USER;<br> R.CreateKey(_PATH);<br> R.OpenKey(_PATH, False);<br> if R.ReadBinaryData('NoDrives', Buffer, SizeOf(Buffer)) = 0 then Buffer := 0;<br> Buffer := Buffer and not Mask or Mask; // 为了不破坏对其它驱动器的设置。<br> R.WriteBinaryData('NoDrives', Buffer, SizeOf(Buffer));<br> R.Free;<br>end;<br><br>