How to running application under root privilege?

こ雲淡風輕ζ 提交于 2019-12-12 00:41:54

问题


Please tell me a way grant for my application to modify /Library/Fonts folder as add new and remove font file. Thanks in advance.


回答1:


  • You can split your application into two parts: service(daemon) and UI and install them via installer in the way so your service will have root privileges
  • You can run some command from your app using AuthorizationExecuteWithPrivileges() but it is deprecated. Still it works
  • You can run some command via NSAppleScript using "do shell script \"some script\" with administrator privileges". But it more like a hack and apple documentation says that NSAppleScript class must be used only from the main thread of an application. But it works too, and personally I don't have any troubles with that.
  • You can create helper tool and use ServiceManagement.framework and SMJobBless()

You can find some additional info here and here



来源:https://stackoverflow.com/questions/17713794/how-to-running-application-under-root-privilege

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!