Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I determine the Windows Username?

System Information

How do I determine the Windows Username?

by  Stretchwickster  Posted    (Edited  )
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!)
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top