怎样把HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs分支中的键值及键值数据分别显示在Listbox1中组件中,但是只用二个Listbox1组件)请用代码举例说明。

解决方案 »

  1.   

    Registry:=tregistry.create;
    registry.rootkey:=HKEY_LOCAL_MACHINE;
    registry.openkey('Software\Microsoft\Windows\CurrentVersion\SharedDlls',True);listbox......
    registry.free;
      

  2.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Reg: TRegistry;
      Val:TStringList;
      I:Integer;
    begin
      Reg:=TRegistry.Create;
      try
        Val:=TStringList.Create;
        try
          Reg.RootKey:=HKEY_LOCAL_MACHINE; // Section to look for within the registry
          if not Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\SharedDlls',False) then
            ShowMessage('Error opening key')
          else
          begin
            Reg.GetKeyNames(Listbox1.Items);
            Reg.GetValueNames(Listbox2.Items);  finally
        Reg.Free;
      end;
    end;
      

  3.   

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Reg: TRegistry;
      Val:TStringList;
      I:Integer;
    begin
      Reg:=TRegistry.Create;
      try
        Val:=TStringList.Create;
        try
          Reg.RootKey:=HKEY_LOCAL_MACHINE; // Section to look for within the registry
          if not Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\SharedDlls',False) then
            ShowMessage('Error opening key')
          else
          begin
            Reg.GetKeyNames(Listbox1.Items);
            Reg.GetValueNames(Listbox2.Items);     end
      finally
        Reg.Free;
      end;
    end;
      

  4.   

    var
      str : TStrings;
      Reg : TRegistry;
      i   : Integer;
      t   : TRegDataInfo;
    begin
      Reg := TRegistry.Create;
      Reg.RootKey := HKEY_LOCAL_MACHINE;
      if reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\SharedDLLs' ,false) then
      begin
        str:=TStringList.Create;
        reg.GetValueNames(str);
        GetClassForm.ListBox1.Items.AddStrings(str);
        for i:=0 to str.Count-1 do
        begin
          reg.GetDataInfo(str[i],t);
          case t.RegData of
            rdString,rdExpandString:ListBox2.Items.Add(
                reg.ReadString(str.Strings[i]));
            rdInteger:ListBox2.Items.Add(
                IntToStr(reg.ReadInteger(str.Strings[i])));
          end;
        end;
        str.Free;
      end;
      Reg.Free;
    end;