【问题标题】:Launching programs as another user on Mac OS X在 Mac OS X 上以其他用户身份启动程序
【发布时间】:2013-03-31 08:18:52
【问题描述】:

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

【问题讨论】:

    标签: objective-c macos runas usersession


    【解决方案1】:

    您需要使用 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);
    

    【讨论】:

      猜你喜欢
      • 2012-01-17
      • 2013-09-18
      • 2016-12-27
      • 1970-01-01
      • 2020-04-09
      • 1970-01-01
      • 1970-01-01
      • 2011-04-11
      • 1970-01-01
      相关资源
      最近更新 更多