获取OS X上的所有用户 [英] Get all Users on OS X

查看:160
本文介绍了获取OS X上的所有用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想在我的应用程序中实现家长控制每个用户,但我需要一种方法来获取所有的用户和添加到一个NSTableView。这些用户应该由登录窗口显示,不包括其他...一个和系统用户。

So I want to implement Parental Controls per user in my app, but I need a way of getting all Users and add them to an NSTableView. These users should be the same displayed by the Login Window, excluding the Other... one and system users.

有关如何做的任何想法?此外,我想要能够在该表视图上选择,当然更改显示的设置。

Any ideas on how to do this? Also, I want to be able to get the selection on that table view and of course change the settings displayed according to that.

推荐答案

这是我如何做的:

#import <CoreServices/CoreServices.h>
#import <Collaboration/Collaboration.h>

CSIdentityAuthorityRef defaultAuthority = CSGetLocalIdentityAuthority();
CSIdentityClass identityClass = kCSIdentityClassUser;

CSIdentityQueryRef query = CSIdentityQueryCreate(NULL, identityClass, defaultAuthority);

CFErrorRef error = NULL;
CSIdentityQueryExecute(query, 0, &error);

CFArrayRef results = CSIdentityQueryCopyResults(query);

int numResults = CFArrayGetCount(results);

NSMutableArray * users = [NSMutableArray array];
for (int i = 0; i < numResults; ++i) {
    CSIdentityRef identity = (CSIdentityRef)CFArrayGetValueAtIndex(results, i);

    CBIdentity * identityObject = [CBIdentity identityWithCSIdentity:identity];
    [users addObject:identityObject];
}

CFRelease(results);
CFRelease(query);

//users contains a list of known Aqua-style users.

CBIdentity 对象使用比 CSIdentityRef 对象,但他们需要导入Collaboration框架。

The CBIdentity objects are much more convenient to use than the CSIdentityRef objects, but they do require importing the Collaboration framework.

这篇关于获取OS X上的所有用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆