[Lazarus] real user name

Reenen Laurie rlaurie at gmail.com
Wed Jan 14 08:56:46 CET 2009


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}
{$ifdef linux}
  GetUserData(FpGetuid, Data);
  username := Data.pw_uid;
{$endif}

How about MacOS?

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

(I use "users")?

Regards,
-Reenen

On Wed, Jan 14, 2009 at 9:24 AM, Michael Van Canneyt <michael at freepascal.org
> wrote:

>
>
> On Wed, 14 Jan 2009, Reenen Laurie wrote:
>
> > Sorry for digging up an old thread...
> >
> > I just want to know... Is this code crossplatfrom?
> >
> > GetUserData(FpGetuid, Data);
> > > Result.Name:= Data.pw_name;
> > > Result.Real_name:= Data.pw_gecos;
> > > Result.User_id:= Data.pw_uid;
> > > Result.Group_id:= Data.pw_gid;
> > > Result.home_dir:= Data.pw_dir;
> > > Result.shell:= Data.pw_shell;
>
> It definitely won't work on Windows, but all unix-like platforms should be
> fine.
>
> Michael.
>
> > >
> >
> > If not, is some of it?  Specifically the Data.pw_name
> >
> > Regards,
> > -Reenen
> >
> >
> > On Thu, Dec 4, 2008 at 11:23 AM, Andrea Mauri <andrea.mauri.75 at gmail.com
> >wrote:
> >
> > > Marco van de Voort ha scritto:
> > > > In our previous episode, Andrea Mauri said:
> > > >
> > > >> I solved using GetUserData procedure from users unit.
> > > >>
> > > >>   GetUserData(FpGetuid, Data);
> > > >>   Result.Name:= Data.pw_name;
> > > >>   Result.Real_name:= Data.pw_gecos;
> > > >>   Result.User_id:= Data.pw_uid;
> > > >>   Result.Group_id:= Data.pw_gid;
> > > >>   Result.home_dir:= Data.pw_dir;
> > > >>   Result.shell:= Data.pw_shell;
> > > >>
> > > >
> > > > Note that that avoids _unit_ libc but not _library_ libc.
> > > >
> > > > That said, the above example code will probably work well on FreeBSD
> and
> > > OS
> > > > X too (contrary to _unit_ libc)
> > > >
> > >
> > > That's what I want.
> > > a.
> > >
> > > > _______________________________________________
> > > > Lazarus mailing list
> > > > Lazarus at lazarus.freepascal.org
> > > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
> > > >
> > > >
> > >
> > > --
> > > Dr. Andrea Mauri, PhD
> > > Milano Chemometrics and QSAR Research Group
> > > Department of Environmental Sciences
> > > University of Milano-Bicocca
> > > P.zza della Scienza, 1
> > > 20126 Milano - Italy
> > >
> > > Tel: ++39 02 64482801
> > > mailto:andrea.mauri.75 at gmail.com
> > > http://michem.disat.unimib.it/chm/
> > >
> > > _______________________________________________
> > > Lazarus mailing list
> > > Lazarus at lazarus.freepascal.org
> > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
> > >
> >
> >
> >
> > --
> > o__
> > ,_.>/ _
> > (_)_\(_)_______
> > ...speed is good
> > _______________
> > I believe five out of four people have a problem with fractions.
> >
> _______________________________________________
> Lazarus mailing list
> Lazarus at lazarus.freepascal.org
> http://www.lazarus.freepascal.org/mailman/listinfo/lazarus
>



-- 
o__
,_.>/ _
(_)_\(_)_______
...speed is good
_______________
I believe five out of four people have a problem with fractions.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20090114/b53cc917/attachment-0007.html>


More information about the Lazarus mailing list