Ler o user logado

Delphi

19/02/2003

Quero saber como posso saber o nome do utilizador logado em windows 2000


Pedro

Pedro

Curtidas 0

Respostas

Carnette

Carnette

19/02/2003

function LogUser : String;
{Requer a unit Registry declarada na clausula Uses da Unit}
var
Registro:TRegistry;
begin
Registro := TRegistry.Create;
Registro.RootKey := HKEY_LOCAL_MACHINE;
if Registro.OpenKey(´Network\Logon´, false) then
begin
result := Registro.ReadString(´username´);
end;
Registro.Free;
end;


GOSTEI 0
Dor_poa

Dor_poa

19/02/2003

ou use esta aqui..

function TForm1.usuario : string;
var
szNetName: Array[0..48] of Char;
iResult: DBIResult;
begin
iResult:= DBIGetNetUserName(szNetName);
if iResult <> DBIErr_None then
DBIError( iResult )
else
Result:= StrPas(szNetName);
end;


As 2 funcionam em 2000


GOSTEI 0
POSTAR