开发者

Get the logged-in User's Name on Mac OS X 10.5

Please let me know of any example code or Cocoa API to get the logged-i开发者_如何学运维n user's name on Mac OS X 10.5.


The Foundation framework provides functions to obtain the user name and the full user name:

#import <Foundation/Foundation.h>

NSString *userName = NSUserName();
NSString *fullUserName = NSFullUserName();


If your process running in as root. And you want current login user then you can use SCDynamicStoreCopyConsoleUser(SCDynamicStoreRef store, uid_t *uid, gid_t *gid) which is present in systemConfiguretion framework.

use it as CFStringRef cfName = SCDynamicStoreCopyConsoleUser(NULL, NULL, NULL);

you can get other info by passing parameter to function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜