Recent

Author Topic: how to get the username  (Read 18115 times)

a.atalla

  • Jr. Member
  • **
  • Posts: 82
how to get the username
« on: July 07, 2010, 12:42:07 pm »
i need the user name to use in my application
i couldnot found the function that returns the user-name  in linux
Lazarus 1.0.8 | FPC 2.6.2 x64  | Arch Linux x64 | Windows 7-x86

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: how to get the username
« Reply #1 on: July 07, 2010, 12:55:34 pm »
GetEnvironmentVariable('USER');         

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: how to get the username
« Reply #2 on: July 07, 2010, 01:44:37 pm »
GetEnvironmentVariable('USERNAME');   

a.atalla

  • Jr. Member
  • **
  • Posts: 82
Re: how to get the username
« Reply #3 on: July 07, 2010, 04:15:24 pm »
GetEnvironmentVariable('USER');         

that works ,but now my application will run with root priviliage so that function will return "root"  as the user name
is there any way i can list all the computer users "not only the current user" ?
Lazarus 1.0.8 | FPC 2.6.2 x64  | Arch Linux x64 | Windows 7-x86

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: how to get the username
« Reply #4 on: July 07, 2010, 04:49:58 pm »
What do you want to achieve?
Sounds like you don't know yourself ;-)

http://forum.lazarus.freepascal.org/index.php/topic,9770.msg48175.html#msg48175

a.atalla

  • Jr. Member
  • **
  • Posts: 82
Re: how to get the username
« Reply #5 on: July 07, 2010, 05:01:20 pm »

GetEnvironmentVariable('USER');         
this one was what i'm looking for but now i need another thing

my application will run on the user machine with root privilege ,and it will do some admin stuff on other users account ,so i need to know what the other users that use the computer

i wish that is clear

does the post u linked belongs to my question?
Lazarus 1.0.8 | FPC 2.6.2 x64  | Arch Linux x64 | Windows 7-x86

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: how to get the username
« Reply #6 on: July 07, 2010, 05:11:41 pm »
does the post u linked belongs to my question?

Yes.

Laksen

  • Hero Member
  • *****
  • Posts: 728
    • J-Software
Re: how to get the username
« Reply #7 on: July 07, 2010, 07:49:54 pm »
It's easy.

Take a look at the users unit in the users fpc package. It contains everything you need. GetUserList, and GetUserData combined with FpGetuid from baseunix sounds like what you want :)

That's ofcourse a very unix specific unit :)

 

TinyPortal © 2005-2018