osx-如何以编程方式删除具有提升权限的文件? [英] osx - How to programmatically delete a file with elevated privileges?

查看:106
本文介绍了osx-如何以编程方式删除具有提升权限的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从〜/Library/PreferencePanes文件夹中删除文件,而使用普通特权无法完成此操作.通常,如果您需要从〜/Library文件夹中删除任何文件,系统将询问您的用户名和密码.

I'm trying to remove a file form the ~/Library/PreferencePanes folder, and this cannot be done with normal privileges. Usually, if you need to delete any file from the ~/Library folder the system will ask for your username and password.

我目前的操作方式是

[[NSFileManager defaultManager] removeItemAtPath:filePath error:&error]

但这会继续返回错误([error localizedDescription]):

but this keeps on returning an error ([error localizedDescription]):

theAppName.prefPane couldn’t be removed because you don’t have permission to access it.

我需要使用什么逻辑和代码来获得删除文件所需的这些提升的特权?

What logic and code would I need to use in order to gain these elevated privileges needed for deleting files?

谢谢!

推荐答案

您应该仔细阅读

You should go through the Authorization Services Programming Guide. You will need to use AuthorizationExecuteWithPrivileges.

这篇关于osx-如何以编程方式删除具有提升权限的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆