繁体   English   中英

在Mac OS X上以其他用户身份启动程序

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM