Mega Code Archive

 
Categories / Delphi / System
 

How do I determine the Windows Username

Title: How do I determine the Windows Username? CODE function GetWindowsUserName: String; const MAX_LENGTH = 256; var UserNameLength: DWord; begin UserNameLength := MAX_LENGTH - 1; SetLength(Result, MAX_LENGTH); if GetUserName(PChar(Result), UserNameLength) then SetLength(Result, UserNameLength - 1) else Result := '; end; Sources: http://www.infojet.cz/program/delphi/tips/tip0006.html http://www.assu-assist.nl/pgg/70.shtml http://msdn.microsoft.com/library/default.asp?url=/library/en-us/sysinfo/base/getusername.asp Contributor: Andrew aka towerbase (yet again the "master programming proof-reader" Andrew slimmed my code - thank you!)