Get registered username in Mac OS X 10.5

Please let me know some sample Cocoa code or API to get the username of the logged in Mac OS X 10.5.

+6
cocoa macos
source share
2 answers

The fundamental structure provides functions for obtaining the username and full username:

#import <Foundation/Foundation.h> NSString *userName = NSUserName(); NSString *fullUserName = NSFullUserName(); 
+24
source share

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

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

You can get other information by passing a function parameter.

+2
source share

All Articles