Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   How to get user information (http://www.velocityreviews.com/forums/t440666-how-to-get-user-information.html)

msc 12-27-2005 12:11 PM

How to get user information
 
Hi guys,
How to get the user information like userid written in C
language.


Mark McIntyre 12-27-2005 01:23 PM

Re: How to get user information
 
On 27 Dec 2005 04:11:29 -0800, in comp.lang.c , "msc"
<mscmailid@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 =----

Kenny McCormack 12-27-2005 01:34 PM

Re: How to get user information
 
In article <20g2r1pi6v79nkch8bne18ce26bjjibjn7@4ax.com>,
Mark McIntyre <markmcintyre@spamcop.net> wrote:
>On 27 Dec 2005 04:11:29 -0800, in comp.lang.c , "msc"
><mscmailid@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.


Flash Gordon 12-27-2005 01:34 PM

Re: How to get user information
 
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.

Richard Heathfield 12-27-2005 02:36 PM

Re: How to get user information
 
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)

Stan Milam 12-27-2005 02:44 PM

Re: How to get user information
 
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.

Keith Thompson 12-27-2005 04:45 PM

Re: How to get user information
 
Stan Milam <stmilam@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) kst-u@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.

Kenneth Brody 01-03-2006 09:40 PM

Re: How to get user information
 
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:ThisIsASpamTrap@gmail.com>



All times are GMT. The time now is 06:38 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.