如何在cocoa application中执行管理员操作

来源:互联网 发布:手机淘宝首页免费模板 编辑:程序博客网 时间:2024/05/22 13:09

其中path_load是一个可执行文件的名称(包含了路径),args是传入的参数。

界面会跳出提示框,输入密码后,可以执行path_load(管理员的操作放卸载 path_load这个可执行文件中)


 // Create authorization reference
 AuthorizationRef authorizationRef;
 OSStatus status = AuthorizationCreate(NULL, kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults, &authorizationRef);
 
 
 const char *args[] = {szCpCmd,"","load"};
 //load
 status = AuthorizationExecuteWithPrivileges(authorizationRef, path_load,kAuthorizationFlagDefaults, args, NULL);
 
 AuthorizationFree(authorizationRef, kAuthorizationFlagDefaults);
 

 

 

附:http://www.cocoachina.com/macdev/cocoa/2010/0831/2074.html

0 0
原创粉丝点击