1

在具有多个用户的 Mac OS X 中,是否有任何 API 或一段代码可以在 Objective C 中以另一个用户身份运行进程?

4

1 回答 1

2

您需要使用AuthorizationExecuteWithPrivileges,看看例如http://www.michaelvobrien.com/blog/2009/07/authorizationexecutewithprivileges-a-simple-example/

// Create authorization reference
AuthorizationRef authorizationRef;
OSStatus status;
status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,
                             kAuthorizationFlagDefaults, &authorizationRef);

// Run the tool using the authorization reference
char *tool = "/sbin/dmesg";
char *args[] = {NULL};
FILE *pipe = NULL;
status = AuthorizationExecuteWithPrivileges(authorizationRef, tool,
                                            kAuthorizationFlagDefaults, args, &pipe);
于 2013-03-31T08:25:17.497 回答