2013-03-31 50 views

回答

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); 
相关问题