• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Getting current user short name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Getting current user short name


  • Subject: Re: Getting current user short name
  • From: Stephan Cleaves <email@hidden>
  • Date: Tue, 7 Nov 2006 19:35:53 -0500

I believe the most correct way to achieve this is by using the SystemConfiguration framework. There is good information on how to do that in Advanced Mac OS X Programming. ADC's page on it is here:

http://developer.apple.com/documentation/Networking/Reference/ SysConfig/index.html

The following is less code but may give the result you are seeing from CGSessionCopyCurrentDictionary and may also not be a completely valid way to do it:

NSString *userName = [[[NSProcessInfo processInfo] environment] objectForKey:@"USER"];

Stephan

On Nov 7, 2006, at 7:03 PM, Eric Blanpied wrote:

Is there some standard way to get the current short user name?


I'm using this code, which I cribbed from a developer.apple.com page on supporting fast user switching. It works fine on my development machine, but on a machine that's only got one account, it turns out it's not the right answer. Makes sense, I guess.


CFStringRef shortUserName;
CFDictionaryRef sessionInfoDict;

sessionInfoDict = CGSessionCopyCurrentDictionary();
if (sessionInfoDict == NULL)
	NSLog(@"Unable to get session dictionary.");

shortUserName = CFDictionaryGetValue(sessionInfoDict, kCGSessionUserNameKey);



_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Getting current user short name (From: Eric Blanpied <email@hidden>)

  • Prev by Date: Re: Getting current user short name
  • Next by Date: Re: Polished metal.. and tabview!
  • Previous by thread: Re: Getting current user short name
  • Next by thread: Re: Getting current user short name
  • Index(es):
    • Date
    • Thread