objective c - Remove Helper Tool using NSTask in MAC Application -
i working on mac application in doing stuff root privilege , working fine , want delete helper tools trying delete helper tool using nstask below code.
nstask *task = [[nstask alloc] init]; nsstring *bundlepath = [[nsbundle mainbundle] pathforresource:@"uninstall" oftype:@"sh"]; [task setlaunchpath:bundlepath]; [task setarguments:[nsarray arraywithobjects:@"uninstall.sh", nil]]; [task setstandardoutput:[nspipe pipe]]; [task setstandardinput:[nspipe pipe]]; [task launch]; it prompt user password says permission denied.
below code use delete helper tool mac admin privileges.
in fullscript write terminal command , try.
-(void)removehelpertoolfrommac{ nsstring * fullscript = @"write terminal code here"; nsdictionary *errorinfo = [nsdictionary new]; nsstring *script = [nsstring stringwithformat:@"do shell script \"%@\" administrator privileges", fullscript]; nsapplescript *applescript = [[nsapplescript new] initwithsource:script]; nsappleeventdescriptor * eventresult = [applescript executeandreturnerror:&errorinfo]; // check errorinfo if (!eventresult) { // describe common errors nsstring *errordescription = nil; if ([errorinfo valueforkey:nsapplescripterrornumber]) { nsnumber * errornumber = (nsnumber *)[errorinfo valueforkey:nsapplescripterrornumber]; if ([errornumber intvalue] == -128) errordescription = @"the administrator password required this."; } // set error message provided message if (errordescription == nil) { if ([errorinfo valueforkey:nsapplescripterrormessage]) errordescription = (nsstring *)[errorinfo valueforkey:nsapplescripterrormessage]; } } else { // set output applescript's output // delete files } } hope you.
Comments
Post a Comment