Ver Mensaje Individual
  #12  
Antiguo 28-02-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola Marton.
Cita:
Empezado por martonbarbosa Ver Mensaje
y con respeto a tu codigo ecfisa, anda... pero el tema es que yo tengo que escribir a mano la ruta entera...
Si, eso es lo que había entendido que deseabas hacer...

Aunque nlsgarcia ya te dió una muy buena solución, otra opción para lograrlo es:
Código Delphi [-]
uses Registry;

procedure TForm1.FindValueName(aRootKey: HKEY; aKeyName, aValueName: string;
  StResult: TStrings);
var
  Registry: TRegistry;
  RegDataType: TRegDataType;
  SKeys: TStringList;
  SValues: TStringList;
  i, size: integer;
  st: string;
begin
  with TRegistry.Create do
  try
    RootKey := aRootKey;
    if OpenKeyReadOnly(aKeyName) then
    begin
      SValues := TStringList.Create;
      try
        GetValueNames(SValues);
        for i := 0 to SValues.count - 1 do
        begin
          RegDataType :=  GetDataType(SValues[i]);
          case RegDataType of
            rdUnknown : st := 'Desconocido';
            rdInteger : st := IntToStr(ReadInteger(SValues[i]));
            rdString , rdExpandString : st := ReadString(SValues[i]);
            rdBinary  : begin
                          size:= GetDataSize(SValues[i]);
                          SetLength(st, size);
                          ReadBinaryData(SValues[i], PChar(st)^, size);
                        end;
          end;
          if SValues[i] = aValueName  then
            StResult.Add(aKeyName + '\' + SValues[i] + ' = ' + st)
        end;
      finally
        SValues.Free
      end;
    end;
    SKeys := TStringList.Create;
    try
      GetKeyNames(SKeys);
      for i := 0 to SKeys.count - 1 do
        FindValueName(aRootKey, aKeyName + '\' + SKeys[i], aValueName, StResult);
    finally
      SKeys.Free;
    end;
  finally
    Free;
  end;
end;

Llamada ejemplo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  FindValueName(HKEY_LOCAL_MACHINE,
               'HARDWARE\DESCRIPTION\System',
               'Identifier',
               ListBox1.Items);
end;
Al parámetro aKeyName podés especificarle cualquier ruta. Lógicamente cuando más próxima al valor la especifiques más rápidamente realizará la búsqueda, pero será menos amplia.

Con una pequeña modificación también podes buscar en el registro completo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
const
  HKEYCONST : array[0..6] of HKEY = (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER,
    HKEY_LOCAL_MACHINE, HKEY_USERS, HKEY_PERFORMANCE_DATA,HKEY_CURRENT_CONFIG,
    HKEY_DYN_DATA);
var
  i: Integer;
begin
  for i:= Low(HKEYCONST) to High(HKEYCONST) do
    FindValueName(HKEYCONST[i],
                  '',
                  'Profile',
                  ListBox1.Items);
end;
Pero debes armarte de paciencia...

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita