How to get currently logged in username?

前端 未结 2 927
灰色年华
灰色年华 2020-12-16 15:27

How do you get the currently logged in username in a Firemonkey Delphi project? I\'m targeting both Windows and Mac.

I have XE2, but I suppose any version solution i

2条回答
  •  無奈伤痛
    2020-12-16 15:45

    Another simpler solution is to get the computer name via the environment variable using GetEnvironmentVariable function as follows:

    Result := GetEnvironmentVariable('USERNAME');
    

    P.S.This solution is for Windows and Linux but you need to check your Delphi source code if it is supported.

提交回复
热议问题