• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Launch process as root from cocoa app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Launch process as root from cocoa app


  • Subject: Launch process as root from cocoa app
  • From: Nyxem <email@hidden>
  • Date: Mon, 25 Jan 2010 08:57:33 +0100

Hello,

I'm currently working on a Preference Pane with an SFAuthorizationView, my problem is simple, when I click on a switch button I need to start / stop a daemon as user using launchctl.
I tried 3 different ways and the only one that is working is the slowest, here the 3 ways I tried :

1 - Using the authorizationRef object of my SFAuthorizationView and call AuthorizationExecuteWithPrivileges() ("/bin/launchctl load /Library/LaunchDaemons/com.mydaemon.plist")
	--> Failed. daemon not launched as root, but as current user.

2 - Using /usr/bin/security with an NSTask : "/usr/bin/security execute-with-privileges /bin/launchctl load /Library/LaunchDaemons/com.mydaemon.plist"
	--> Failed. daemon not launched as root, but as current user + ask a second time for an admin password..

3 - Using AppleScript :
NSAppleScript *script = [[NSAppleScript alloc] initWithSource:@"do shell script \"/bin/launchctl load /Library/LaunchDaemons/com.mydaemon.plist\" with administrator privileges"];
NSDictionary *errorInfo;
[script executeAndReturnError:&errorInfo];
[script release];
	--> Worked but very slow and I have to re-enter an admin password, which is very annoying.

So is there any other way to do this without enter 2 times an admin password ?

Thanks for your help.

Nyxem.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Launch process as root from cocoa app
      • From: Nick Zitzmann <email@hidden>
    • Re: Launch process as root from cocoa app
      • From: Kyle Sluder <email@hidden>
  • Prev by Date: Re: simple file browser
  • Next by Date: Re: Launch process as root from cocoa app
  • Previous by thread: Re: Focus Ring and NSTextField
  • Next by thread: Re: Launch process as root from cocoa app
  • Index(es):
    • Date
    • Thread