当前位置: 动力学知识库 > 问答 > 编程问答 >

objective c - Launching programs as another user on Mac OS X

问题描述:

In a Mac OS X with more than one users , is there any API or piece of code that Run a process as another user in Objective C?

网友答案:

You need to use AuthorizationExecuteWithPrivileges, take a look e.g. at 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);
分享给朋友:
您可能感兴趣的文章:
随机阅读: