Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2008-12

real user name

11 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrea Mauri
Hi,
there is a way in order to get the real name of a linux/windows user?
In order to get the login name (linux) I used:
  Result.Name:= GetEnvironmentVariable('USERNAME');
  if Result.Name = '' then
    Result.Name:= GetEnvironmentVariable('USER');

I know that in linux I can use libc (getpwuid(fpgetuid)^.pw_gecos) but I am trying to avoid use of libc.
Any suggestion?
Andrea

Reply by email

Graeme Geldenhuys
to Andrea Mauri
Andrea Mauri wrote 6 lines
there is a way in order to get the real name of a linux/windows user? In order to get the login name (linux) I used: Result.Name:= GetEnvironmentVariable('USERNAME'); if Result.Name = '' then Result.Name:= GetEnvironmentVariable('USER');

That is exactly how we have been using it as well - for the last 4 years. No issues so far.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email

Marco van de Voort
to Andrea Mauri: there is a way in order to get the real name of a linux/windows user? In order to get the…
Andrea Mauri wrote 8 lines
there is a way in order to get the real name of a linux/windows user? In order to get the login name (linux) I used: Result.Name:= GetEnvironmentVariable('USERNAME'); if Result.Name = '' then Result.Name:= GetEnvironmentVariable('USER'); I know that in linux I can use libc (getpwuid(fpgetuid)^.pw_gecos) but I am trying to avoid use of libc.

Have a look at the users package. This is afaik 2.2.2+ though.

Reply by email

Andrea Mauri
to Marco van de Voort

Thanks Marco.
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;

Marco van de Voort ha scritto:

Show quoted text 19 lines
On Tue, Dec 02, 2008 at 10:02:57PM +0100, Andrea Mauri wrote: > there is a way in order to get the real name of a linux/windows user? > In order to get the login name (linux) I used: > Result.Name:= GetEnvironmentVariable('USERNAME'); > if Result.Name = '' then > Result.Name:= GetEnvironmentVariable('USER'); > > I know that in linux I can use libc (getpwuid(fpgetuid)^.pw_gecos) but I > am trying to avoid use of libc. > Have a look at the users package. This is afaik 2.2.2+ though. _______________________________________________ Lazarus mailing list 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: http://michem.disat.unimib.it/chm/

Reply by email

Marco van de Voort
to Andrea Mauri

In our previous episode, Andrea Mauri said:

Show quoted text 9 lines
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)

Reply by email

Andrea Mauri
to Marco van de Voort

Marco van de Voort ha scritto:

Show quoted text 18 lines
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.

Show quoted text 6 lines
_______________________________________________ Lazarus mailing list 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: http://michem.disat.unimib.it/chm/

Reply by email

Reenen Laurie
to Andrea Mauri

Sorry for digging up an old thread...

I just want to know... Is this code crossplatfrom?

GetUserData(FpGetuid, Data);
Show quoted text 7 lines
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;

If not, is some of it? Specifically the Data.pw_name

Regards,
-Reenen

Andrea Mauri wrote 48 lines
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 > > 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: http://michem.disat.unimib.it/chm/ _______________________________________________ Lazarus mailing list 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://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090114/5a74c810/attachment.html

Reply by email

Michael Van Canneyt
to Reenen Laurie
Reenen Laurie wrote 11 lines
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.

Show quoted text 69 lines
> If not, is some of it? Specifically the Data.pw_name Regards, -Reenen On Thu, Dec 4, 2008 at 11:23 AM, Andrea Mauri 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 > > > > 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: > http://michem.disat.unimib.it/chm/ > > _______________________________________________ > Lazarus mailing list > > http://www.lazarus.freepascal.org/mailman/listinfo/lazarus > -- o__ ,_.>/ _ (_)_\(_)_______ ...speed is good _______________ I believe five out of four people have a problem with fractions.

Reply by email

Reenen Laurie
to Michael Van Canneyt

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 <

Show quoted text 99 lines
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 < >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 > > > > > > 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: > > http://michem.disat.unimib.it/chm/ > > > > _______________________________________________ > > Lazarus mailing list > > > > 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 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://www.lazarus.freepascal.org/pipermail/lazarus/attachments/20090114/b53cc917/attachment-0001.html

Reply by email

Michael Van Canneyt
to Reenen Laurie
Reenen Laurie wrote 6 lines
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.

Show quoted text 6 lines
{$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.

Reply by email

Graeme Geldenhuys
to Reenen Laurie: Ok, so if I want code in which I want to get the username, which is crossplatform... how…

2009/1/14 Reenen Laurie :

{$ifdef windows} username := GetEnvironmentVariable('USERNAME'); {$endif}

Nope, change that to something like:

var
  userNameBuffer: array[0..255] of char;
  sizeBuffer: DWord;
begin
  SizeBuffer := 256;
  getUserName(userNameBuffer, sizeBuffer);
  result := string(userNameBuffer);
Show quoted text 6 lines
{$ifdef linux} GetUserData(FpGetuid, Data); username := Data.pw_uid; {$endif} How about MacOS?

Change that to {$ifdef unix} instead.

Regards,
- Graeme -

_______________________________________________
fpGUI - a cross-platform Free Pascal GUI toolkit
http://opensoft.homeip.net/fpgui/

Reply by email