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