Fórum Usuário Logado #269848
23/02/2005
0
Estou utilizando a rotina abaixo para descobrir o usuário logado na estação naquele momento. Acontece que só está funcionando para XP e 2000 e não para 98 e 95. Alguém poderia me ajudar ou mesmo uma outra função que fizesse isso ? Talvez até a nível de registry.
Grato
function TForm1.SysUserName: string;
var
I: DWord;
begin
I := 255;
SetLength(Result, I);
Windows.GetUserName(PChar(Result), I);
Result := string(PChar(Result));
end;
Guilherme B
Curtir tópico
+ 0Posts
23/02/2005
Marcio.theis
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
23/02/2005
Guilherme B
A minha máquina é W2K. No registry não existe esta chave.
Gostei + 0
23/02/2005
Marcio.theis
procedure PegaNetInfo;
var
BufLen : DWORD;
Buffer : PChar;
begin
BufLen := 32+1;
Buffer := #0;
try
GetMem( Buffer, BufLen );
case WNetGetUser(nil, Buffer, BufLen) of
NO_ERROR: SysInfoRec.UserConName := Buffer;
ERROR_NOT_CONNECTED: SysInfoRec.UserConName := ´Not Connected´;
ERROR_NO_NETWORK: SysInfoRec.UserConName := ´No Network´;
else SysInfoRec.UserConName := ´Other Network error´;
end;
finally
FreeMem( Buffer );
end; // try
end; {- GetNetInfo }
function NomeUsuario: string;
begin
PegaNetInfo();
Result:=SysInfoRec.UserConName;
end;
edt.Text:=NomeUsuario;
Gostei + 0
23/02/2005
Guilherme B
Está dando erro na SysInfoRec.
Qual biblioteca eu preciso colocar na Uses ?
Gostei + 0
23/02/2005
Marcio.theis
private
{ Private declarations }
usuario: string;
depois onde tiver SysInfoRec.UserConName troque por usuario.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)