如何使用NSTask作为根? [英] How to use NSTask as root?

查看:935
本文介绍了如何使用NSTask作为根?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个应用程序中,我需要以root用户身份运行以下命令(如果用户真的想要提示trice,他们将被要求卸载他们的驱动器):

In an application I'm making I need to run the following command as root (user will be prompted trice if they really want to, and they will be asked to unmount their drives) using NSTask:

/bin/rm -rf /
#Yes, really

问题是,简单地使用替代用户做( sudo )不能工作,因为用户需要输入密码不可用的stdin。我想向用户显示与单击Preferences.app中的锁定相同的窗口,如下所示(希望使用较短的密码):

The problem is that simply using Substitute User Do (sudo) doesn't work as the user needs to enter the password to the non-available stdin. I'd rather like to show the user the same window as you'd see when you click the lock in Preferences.app, like this (hopefully with a shorter password):

任何人都可以帮我吗?感谢。

Can anyone help me with this? Thanks.

推荐答案

查看 STPrivilegedTask ,一个有着NSTask类接口的AuthorizationExecuteWithPrivileges()的Objective-C包装类。

Check out STPrivilegedTask, an Objective-C wrapper class around AuthorizationExecuteWithPrivileges() with an NSTask-like interface.

这篇关于如何使用NSTask作为根?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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