[Lazarus] real user name

Michael Van Canneyt michael at freepascal.org
Wed Jan 14 09:36:08 CET 2009



On Wed, 14 Jan 2009, Reenen Laurie wrote:

> Ok, so if I want code in which I want to get the username, which is
> crossplatform... how should it look?
> 
> {$ifdef windows}
>   username := GetEnvironmentVariable('USERNAME');
> {$endif}

I'm not sure if this is correct; There is a windows call to get the
current user name.

> {$ifdef linux}
>   GetUserData(FpGetuid, Data);
>   username := Data.pw_uid;
> {$endif}
> 
> How about MacOS?

For MacOS the linux construct should work ?

> 
> Also, as a matter of interest... what types are FpGetuid and Data?

Integer (or word) and pw_nam, I think ?

Michael.



More information about the Lazarus mailing list