Ver Mensaje Individual
  #3  
Antiguo 24-02-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
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
Cita:
Empezado por KroSaver Ver Mensaje
...intento sacar el nombre de usuario atravez del registro de win usando apis en delphi...
Hola KroSaver.

Código Delphi [-]
...
{$WARNINGS OFF}

function ReadRegistryValue(const aKEY: HKEY; const lpSubkey, lpValueName: PChar): string;
var
  lpType   : DWORD;
  lpcbData : DWORD;
  lpData   : PChar;
  phkResult: HKEY;
begin
  if RegOpenKeyEx(aKEY, lpSubkey, 0, KEY_READ, phkResult) = ERROR_SUCCESS then
  begin
    SetLastError(RegQueryValueEx(phkResult, lpValueName, nil, @lpType, nil, @lpcbData));
    if GetLastError = ERROR_SUCCESS then
    begin
      GetMem(lpData, lpcbData);
      try
        RegQueryValueEx(phkResult, lpValueName, nil, nil, PBYTE(lpData), @lpcbData);
        Result := StrPas(lpData)
      finally
        FreeMem(lpData)
      end
    end
    else
      raise Exception.Create('No se pudo obtener el valor de ' + StrPas(lpValueName));
    RegCloseKey(phkResult);
  end;
end;

Llamada de ejemplo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  SubKey, ValueName: string;
begin
  SubKey    := 'SOFTWARE\Microsoft\Windows NT\CurrentVersion';
  ValueName := 'RegisteredOwner';
  ShowMessage('Propietario registrado: '+
    ReadRegistryValue(HKEY_LOCAL_MACHINE, PChar(SubKey), PChar(ValueName)));
end;

Saludos.
__________________
Daniel Didriksen

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