要使用writeinteger才能写入dword值,具体写法如下;
procedure TForm1.Button1Click(Sender: TObject);
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Policies',
True)
    then Reg.WriteInteger('System',139);
  finally
    Reg.CloseKey;
    Reg.Free;
    inherited;
  end;
end;

解决方案 »

  1.   

    既然是DWORD的值,就不要用WriteString,而要用WriteInteger写入。
    procedure TMainForm.Button1Click(Sender: TObject);
    const
      RootKey = HKEY_LOCAL_MACHINE;
    var
      Reg: TRegistry;begin
      Reg := TRegistry.Create;
      try
        Reg.RootKey := RootKey;
        Reg.OpenKey('SoftWare\Microsoft\Windows\CurrentVersion\Policies\System\',
          True);  // True means if the Key not exists, it
                                          // will be created automation.
        Reg.WriteInteger('DisableRegistryTools', $0001);
      finally
        if Assigned(Reg) then
          Reg.Free;
      end;
    end;