By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,199 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

How to get user information

P: n/a
msc
Hi guys,
How to get the user information like userid written in C
language.

Dec 27 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 27 Dec 2005 04:11:29 -0800, in comp.lang.c , "msc"
<ms*******@gmail.com> wrote:
Hi guys,
How to get the user information like userid written in C
language.


You can't do this in standard C - you'd have to use some operating
system specific extension.
Ask again in a group specialising in your compiler or OS, and consider
whether your OS stores this in the user's environment or something.
Mark McIntyre
--

----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Dec 27 '05 #2

P: n/a
In article <20********************************@4ax.com>,
Mark McIntyre <ma**********@spamcop.net> wrote:
On 27 Dec 2005 04:11:29 -0800, in comp.lang.c , "msc"
<ms*******@gmail.com> wrote:
Hi guys,
How to get the user information like userid written in C
language.


You can't do this in standard C - you'd have to use some operating
system specific extension.
Ask again in a group specialising in your compiler or OS, and consider
whether your OS stores this in the user's environment or something.


I.e.:

Not portable. Can't discuss it here. Blah, blah, blah.

Dec 27 '05 #3

P: n/a
msc said:
Hi guys,
How to get the user information like userid written in C
language.


If the information you seek is stored in environment variables, you can get
it using the ISO C standard function, getenv().

For example:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
const char *user = getenv("USER");
if(user != NULL)
{
printf("User name: [%s]\n", user);
}
return 0;
}

The C Standard does not, of course, guarantee the existence or semantics of
particular environment variables.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Dec 27 '05 #4

P: n/a
msc wrote:
Hi guys,
How to get the user information like userid written in C
language.


You can't in standard C so you will have to ask on a group dedicated to
your system.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Dec 27 '05 #5

P: n/a
Flash Gordon wrote:
msc wrote:
Hi guys,
How to get the user information like userid written in C
language.

You can't in standard C so you will have to ask on a group dedicated to
your system.


True. Usually the operating system has some environment variable used
to identify the user. Under Windoze it is "username" and with UNIX it
is usually "LOGNAME." So, look around on your operating system and
determine what environment variable is.
Dec 27 '05 #6

P: n/a
Stan Milam <st*****@swbell.net> writes:
Flash Gordon wrote:
msc wrote:
Hi guys,
How to get the user information like userid written in C
language.

You can't in standard C so you will have to ask on a group dedicated
to your system.


True. Usually the operating system has some environment variable used
to identify the user. Under Windoze it is "username" and with UNIX it
is usually "LOGNAME." So, look around on your operating system and
determine what environment variable is.


This illustrates the dangers of posting partial system-specific
answers.

Though standard C provides no way to set or modify an environment
variable, many systems do. On such a system, using an environment
variable to identify a user allows a user to masquerade as someone
else. Whether this is a problem depends on the application.

Many systems provide ways to identify a user (whatever that happens to
mean) in a more reliable manner. See a system-specific newsgroup (or
your documentation) for more details.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 27 '05 #7

P: n/a
Stan Milam wrote:

Flash Gordon wrote:
msc wrote:
Hi guys,
How to get the user information like userid written in C
language.

You can't in standard C so you will have to ask on a group dedicated to
your system.


True. Usually the operating system has some environment variable used
to identify the user. Under Windoze it is "username" and with UNIX it
is usually "LOGNAME." So, look around on your operating system and
determine what environment variable is.


Ooh, goodie!

LOGNAME=root /path/to/program
or
set username=administrator
\path\to\program

:-)
You need to use a system-specific method to return this information, which
may or may not actually be available. (How does one get the username under
MS-DOS, for example?)

--
+-------------------------+--------------------+-----------------------------+
| Kenneth J. Brody | www.hvcomputer.com | |
| kenbrody/at\spamcop.net | www.fptech.com | #include <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------------+
Don't e-mail me at: <mailto:Th*************@gmail.com>

Jan 3 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.