Re: How to find active user in the cocoa
Re: How to find active user in the cocoa
- Subject: Re: How to find active user in the cocoa
- From: Dave DeLong <email@hidden>
- Date: Mon, 10 Aug 2009 09:09:57 -0600
That's a great point, and one that I failed to mention. However, that
is pretty clear in the CSCopyUserName documentation. =)
One less-than-elegant way to find the logged in user might be to run
"ps" and pipe the results through "grep 'Finder'".
Dave
On Aug 10, 2009, at 9:03 AM, Michael Gozzo wrote:
Hi Arun,
You should note that these three methods will give you the username
under which your application is currently executing. This is not
necessarily the "active user" in the case originally described.
A fourth item to add to this list is the NSUserName() function. The
documentation specifies that "NSUserName returns the logon name of the
current user." though I haven't used the function and am not sure
whether or not "current user" refers to the user in the active desktop
session or who is running the executable that calls NSUserName. (I
suspect the latter, but I'm not completely certain).
Michael
On Mon, Aug 10, 2009 at 10:44 AM, Dave DeLong<email@hidden>
wrote:
You can do this in a number of ways.
1. Run an NSTask that executes "who am i"
2. Use NSString to resolve ~/ and pull out the second path component
3. Use CoreService's CSCopyUserName
And probably a host of others. These are the couple I thought of
off the
top of my head.
HTH,
Dave
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden