[英]Launching a Mac OS X (LoginItem) helper app from the main application
[英]Launching programs as another user on Mac OS X
在具有多个用户的Mac OS X中,是否有任何API或代码段可以在Objective C中以另一用户身份运行进程?
您需要使用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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.