Get user name of currently logged in user

This simple function will return name of currently logged in user.

function UserName: String;
var User: PChar;
    i: DWord;
begin
  i := 1024;
  user := StrAlloc(Succ(i));
  if GetUserName(User, i) then Result := StrPas(User)
                          else Result := 'unknown';
end;