在没有授权弹出的情况下运行ShellScript以进行MAC应用程序

时间:2015-05-05 06:29:31

标签: objective-c macos shell root privileges

我正在研究MAC应用程序,我希望删除以前由我的应用程序安装的Helper工具。

我使用STPrivilegedTask来运行我的ShellScript。 以下是我用来实现此目的的代码。

NSString *pathForUninstallFile = [[NSBundle mainBundle] pathForResource:@"Uninstall" ofType:@"sh"];
STPrivilegedTask *taskToRemoveHelperTool = [STPrivilegedTask launchedPrivilegedTaskWithLaunchPath:pathForUninstallFile arguments:[NSArray arrayWithObjects:@"Uninstall.sh", nil]];

这是我的ShellScript Unistall.sh

launchctl unload /Library/LaunchDaemons/com.bsecure.HelperTool.plist
rm /Library/LaunchDaemons/com.appleCompany.HelperTool.plist
rm /Library/PrivilegedHelperTools/com.appleCompany.HelperTool

security -q authorizationdb remove "com.appleCompany.readLicenseKey"
security -q authorizationdb remove "com.appleCompany.newMethod"

现在上面的代码工作正常,但它会询问用户的授权弹出窗口。

我想在没有此授权弹出窗口的情况下运行此脚本。

我已经在另一个问题中搜索,但它们都不适合我,这就是我创建此问题的原因。

1 个答案:

答案 0 :(得分:0)

因此,您希望在不提示用户输入密码的情况下运行具有升级权限的任务?如果是这样,你运气不好,就无法完成。

相关问题