objective c - Asking a user for elevated privileges and elevating the application without an Apple developer certificate -


apparently, of 10.7, authorizationexecutewithprivileges deprecated. general gist of information i've gathered on seems suggest using servicemanagement.framework's smjobbless() function have helper application deployed.

my understanding of though, need developer certificate purchased apple code sign both application , helper process - or not work. correct?

i used authorizationexecutewithprivileges ask user elevated privileges, since needed access running process. without that, app can't work unofficial plugin it's intended to. code signing way way go here? i'm trying avoid purchasing developer certificate due sheer cost of it.

has found alternative ways relaunch application elevated privileges, user permission of course?

@carlosp's answer code escape path & arguments:

- (bool)runprocessasadministrator:(nsstring*)scriptpath                     witharguments:(nsarray*)arguments                            output:(nsstring**)output                  errordescription:(nsstring**)errordescription {      //check path.     if (![scriptpath hasprefix:@"/"]) {         @throw [nsexception exceptionwithname:                     nsinvalidargumentexception reason:@"absolute path required." userinfo:nil];     }      //define script.     static nsapplescript* applescript = nil;     if (!applescript) {         applescript = [[nsapplescript alloc] initwithsource:             @"on run commandwitharguments\n"              "  activate\n"              "  repeat currentargument in commandwitharguments\n"              "      set contents of currentargument quoted form of currentargument\n"              "  end repeat\n"              "  set applescript's text item delimiters space\n"              "  return shell script (commandwitharguments text) administrator privileges\n"              "end run"];     }      //set command.     nsappleeventdescriptor* commandwitharguments = [nsappleeventdescriptor listdescriptor];     [commandwitharguments insertdescriptor:         [nsappleeventdescriptor descriptorwithstring:scriptpath] atindex:0];      //set arguments.     (nsstring* currentargument in arguments) {         [commandwitharguments insertdescriptor:             [nsappleeventdescriptor descriptorwithstring:currentargument] atindex:0];     }      //create target & event.     processserialnumber     processserial   = {0, kcurrentprocess};     nsappleeventdescriptor* scripttarget    =         [nsappleeventdescriptor descriptorwithdescriptortype:typeprocessserialnumber bytes:&processserial length:sizeof(processserialnumber)];     nsappleeventdescriptor* scriptevent     =         [nsappleeventdescriptor appleeventwitheventclass:kcoreeventclass                                                  eventid:kaeopenapplication                                         targetdescriptor:scripttarget                                                 returnid:kautogeneratereturnid                                            transactionid:kanytransactionid];     [scriptevent setparamdescriptor:commandwitharguments forkeyword:keydirectobject];      //run script.     nsdictionary*           errorinfo   = [nsdictionary dictionary];     nsappleeventdescriptor* eventresult = [applescript executeappleevent:scriptevent error:&errorinfo];      //success?     if (!eventresult) {         if (errordescription)             *errordescription = [errorinfo objectforkey:nsapplescripterrormessage];         return no;     } else {         if (output)             *output = [eventresult stringvalue];         return yes;     }  } 

update

in yosemite, do shell script calls version of authorizationexecutewithprivileges embedded in standardadditions.osax.

it's conceivable with administrator privileges option do shell script go away when authorizationexecutewithprivileges does.

personally, continue calling authorizationexecutewithprivileges directly.

do shell script have advantage of reaping process automatically. requires little extra work authorizationexecutewithprivileges.


Comments