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.
精彩评论