Mega Code Archive

 
Categories / Delphi / Examples
 

Get the login name of the current user

You need to use the GetUserName() API call, and pass NIL as the first parameter. See the following example: // Returns the network ID for the current system user. Returns // null string ('') on error. function GetNetUser : Ansistring; var dwI : DWord; begin dwI := MAX_PATH; SetLength (Result, dwI + 1); if WNetGetUser (Nil, PChar (Result), dwI) = NO_ERROR then SetLength (Result, StrLen (PChar (Result))) else SetLength (Result, 0) end;