On 2009 Feb 06, at 13:14, Tom Fortmann wrote:

Is there a way of determining if a GUI user (ignoring remote shells and such) is logged in from a system daemon? It looks like the WindowServer process is started for a user session, but I'm not sure scanning the process list is the best way of tackling this problem. Is there some Apple Event that can be sent to determine this? Please let me know if anyone has any
ideas on how to do this.

Here's what I use.  It seems like it might be what you need.

/*!
 @brief    Returns the string name, unix user ID (uid) and
 unix group ID (id) of the current console user.

 @result   The string representation of the users's name
*/
+ (NSString*)consoleUserNameAndUid_p:(uid_t*)uid_p
                               gid_p:(gid_t*)gid_p ;

#import <SystemConfiguration/SCDynamicStoreCopySpecific.h>

+ (NSString*)consoleUserNameAndUid_p:(uid_t*)uid_p
                               gid_p:(gid_t*)gid_p {
NSString* name = (NSString*)SCDynamicStoreCopyConsoleUser(NULL, uid_p, gid_p) ;
    return [name autorelease] ;
}

To answer your question, compare the answer you get from that to what you get from NSUserName() using -isEqualToString.

For the above to work, your target must link to /System/Library/ Frameworks/SystemConfiguration.framework

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to