DelphiFAQ Home Search:
General :: Programming :: Delphi
General Delphi related information.

Articles:

This list is sorted by recent document popularity (not total page views).
New documents will first appear at the bottom.
Recommended links on this topic:
Featured Article

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;
 

Generated 12:02:02 on Apr 30, 2017