【发布时间】:2015-07-14 18:10:37
【问题描述】:
我正在开发 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"
现在上面的代码可以完美运行,但它会询问用户的授权弹出窗口。
我想在没有此授权弹出窗口的情况下运行此脚本。
我已经搜索了另一个问题,但没有一个对我有用,这就是我创建这个问题的原因。
【问题讨论】:
标签: objective-c macos shell root privileges