ユーザ名の取得

Cocoaに関するヌマタメモ
2008年11月29日 23:32

現在のユーザ名(コンソールで使用されるもの)を取得するには、System Configuration Framework を使用する。

#import <SystemConfiguration/SystemConfiguration.h>

NSString *GetUserName() {
    NSString *ret = nil;
    CFStringRef userName = SCDynamicStoreCopyConsoleUser(NULLNULLNULL);
    if (userName) {
        ret = NSString stringWithString:(NSString *) userName;
        CFRelease(userName);
    }
    return ret;
}

プロジェクトに SystemConfiguration.framework を加えるのを忘れずに。

コメントを書く


トラックバックはありません。

トラックバックURL: http://numata.designed.jp/mt-tb.cgi/81