获取当前用户名? [英] get current user name?

查看:77
本文介绍了获取当前用户名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检索当前登录用户的用户名?我基本上要检查用户是否以root身份登录,如果没有,请退出

程序。


我虽然关于使用LOGNAME环境变量,但如果普通的

用户使用su root,则环境变量仍然具有用户的登录名

名称。

How do I retrieve the username of the currently logged in user? I
basically to check if the user is logged in as root and if not, exit
the program.

I though about using the LOGNAME environment variable, but if a regular
user used su root, the environment variable still has the user''s login
name.

推荐答案

dj ****** ***@snowboard.com 写道:
如何检索当前登录用户的用户名?我基本上要检查用户是否以root用户身份登录,如果没有,请退出程序。

我虽然使用了LOGNAME环境变量,但是如果是常规<用户使用了su root,环境变量仍然有用户的登录名称。
How do I retrieve the username of the currently logged in user? I
basically to check if the user is logged in as root and if not, exit
the program.

I though about using the LOGNAME environment variable, but if a regular
user used su root, the environment variable still has the user''s login
name.




这不是C问题,试试comp .unix.programmer。


Robert Gamble



This is not a C question, try comp.unix.programmer.

Robert Gamble


对不起,我以为可能有一个简单的C函数完成

这个,但我还没能找到。

Sorry, I thought there might be an easy C function that accomplishes
this, but I haven''t been able to find one yet.


dj ********* @ snowboard.com 写道:
如何检索用户名当前登录的用户?我基本上要检查用户是否以root用户身份登录,如果没有,请退出程序。

我虽然使用了LOGNAME环境变量,但是如果是常规<用户使用su root,环境变量仍然具有用户的登录名称。
How do I retrieve the username of the currently logged in user? I
basically to check if the user is logged in as root and if not, exit
the program.

I though about using the LOGNAME environment variable, but if a regular
user used su root, the environment variable still has the user''s login
name.




C中没有标准方法。最好的办法是询问与您选择的平台相关的
a新闻组,

,如comp.unix.programmer。


< OT>如果您可以假设POSIX,请查看是否

getpwuid和getuid做你想做的事。但

对它们的讨论应该在

comp.unix.programmer< / OT>


-David



There is no standard way in C. Your best bet is to ask in
a newsgroup(s) associated with your platform(s) of choice,
such as comp.unix.programmer.

<OT> If you can assume POSIX, look at whether
getpwuid and getuid do what you want. But
discussion on them should be in
comp.unix.programmer </OT>

-David


这篇关于获取当前用户名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆