【发布时间】:2016-03-08 15:08:34
【问题描述】:
我正在开发一个需要启动“openvpn”的 OS X Firemonkey 应用程序,但 OpenVPN 需要管理员权限才能创建隧道接口。
我正在尝试将此博客文章中的第一个示例转换为 Delphi: http://www.michaelvobrien.com/blog/2009/07/authorizationexecutewithprivileges-a-simple-example/
尝试运行此代码,有时会按预期导致授权提示,但单击“确定”会完全冻结调试器并且需要关闭整个系统。它在没有调试器的情况下运行得更好,但有时仍然会冻结...... 在它崩溃几次之前我已经捕获了返回码,它是 errAuthorizationToolExecuteFailure
我对 OSX 的处理方式不是很熟悉,有没有更好的方法? Apple 不建议为此使用AuthorizationExecuteWithPrivileges。我不知道有任何其他方法可以使用所需的权限运行 openvpn。
uses
Macapi.CoreFoundation, Macapi.Foundation, Macapi.Security;
const
kAuthorizationEmptyEnvironment = nil;
procedure TForm1.Button1Click(Sender: TObject);
var
AuthRef: AuthorizationRef;
Status: OSStatus;
begin
Status := AuthorizationCreate(nil,kAuthorizationEmptyEnvironment,kAuthorizationFlagDefaults,@AuthRef);
Status := AuthorizationExecuteWithPrivileges(AuthRef,'/sbin/dmesg',0,'',nil)
end;
【问题讨论】:
标签: macos delphi firemonkey