Einzelnen Beitrag anzeigen

KLS

Registriert seit: 20. Jun 2004
Ort: Berlin
89 Beiträge
 
Delphi 7 Enterprise
 
#7

Re: Shlüssel mit allen Subkeys exportieren?

  Alt 1. Dez 2006, 10:49
irgendwo hab ich mal folgendes aufgeschnappt. und ich denke das is genau das was du suchst.

Delphi-Quellcode:
procedure ExportRegistryBranch(rootsection : cardinal; Regroot,FileName : string);
var
  reg : TRegistry;
  f : Textfile;
  p : PChar;

  procedure ProcessBranch(root : string);
  var
    values,keys : TStringList;
    i,j,k : longint;
    s,t : string;
  begin
    Writeln(f);
    case rootsection of
      HKEY_CLASSES_ROOT : s := 'HKEY_CLASSES_ROOT';
      HKEY_CURRENT_USER : s := 'HKEY_CURRENT_USER';
      HKEY_LOCAL_MACHINE : s := 'HKEY_LOCAL_MACHINE';
      HKEY_USERS : s := 'HKEY_USERS';
      HKEY_PERFORMANCE_DATA : s := 'HKEY_PERFORMANCE_DATA';
      HKEY_CURRENT_CONFIG : s := 'HKEY_CURRENT_CONFIG';
      HKEY_DYN_DATA : s := 'HKEY_DYN_DATA';
    end;
    Writeln(f,'[' + s + '\' + root + ']');
    reg.OpenKey(root,False);
    values := TStringList.Create;
    keys := TStringList.Create;
    reg.GetValuenames(values);
    reg.GetKeynames(keys);
    for i := 0 to values.Count - 1 do
    begin
      s := values[i];
      t := s;
      if s = 'then s := '@else s := '"' + s + '"';
      Write(f,StringReplace(s,'\','\\',[rfReplaceAll]) + '=');
      case reg.Getdatatype(t) of
        rdString,rdExpandString : Writeln(f,'"' + StringReplace(reg.ReadString(t) + '"','\','\\',[rfReplaceAll]));
        rdInteger : Writeln(f,'dword:' + IntToHex(reg.readinteger(t),8));
        rdBinary : begin
                     Write(f,'hex:');
                     j := reg.GetDataSize(t);
                     GetMem(p,j);
                     reg.ReadBinaryData(t,p^,J);
                     for k := 0 to j - 1 do
                     begin
                       Write(f,IntToHex(Byte(p[k]),2));
                       if k <> j - 1 then
                       begin
                         Write(f,',');
                         if (k > 0) and ((k mod 25) = 0) then Writeln(f,'\');
                       end;
                     end;
                     FreeMem(p,j);
                     Writeln(f);
                   end;
              else Writeln(f, '""');
      end;
    end;
    reg.CloseKey;
    values.Free;
    for i := 0 to keys.Count - 1 do ProcessBranch(root + '\' + keys[i]);
    keys.Free;
  end;

begin
  if RegRoot[Length(Regroot)] = '\then delete(Regroot,Length(Regroot),1);
  Assignfile(f,FileName);
  Rewrite(f);
  Writeln(f,'REGEDIT4');
  reg := TRegistry.Create;
  reg.Rootkey := Rootsection;
  ProcessBranch(Regroot);
  reg.Free;
  Close(f);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ExportRegistryBranch(HKEY_LOCAL_MACHINE,'HARDWARE','c:\test.reg');
end;
Thomas H.
  Mit Zitat antworten Zitat