Pegar Usuário Logado na Máquina

19/03/2003

0

Gostaria de saber como pegar o nome do usuário logado no Windows.


Anonymous

Anonymous

Responder

Posts

19/03/2003

Espiridiao

Ai vai:

[color=blue:f891e6588d]
function GetCurrentUserName: string;
var
Len: cardinal;
{ This will have to be Integer, not cardinal, in Delphi 3. }
begin
Len := 255;
{ arbitrary length to allocate for username string, plus one for null terminator }
SetLength(Result, Len - 1);
{ set the length }
GetUserName(PChar(Result), Len);
{ get the username }
SetLength(Result, Len - 1);
{ set the exact length if it succeeded }
end;[/color:f891e6588d]


Responder

19/03/2003

Dor_poa

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;


Colocar na chamada de Uses de sua Unit as seguintes DCUs : DBITYPES, DBIPROCS, DBIERRS, DBTables e DB.


Responder

19/03/2003

Dor_poa

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;


Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar