• 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
Re: Running process as root from Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Running process as root from Cocoa


  • Subject: Re: Running process as root from Cocoa
  • From: "Mitchell Hashimoto" <email@hidden>
  • Date: Mon, 28 Jan 2008 22:03:31 -0800

Hi,

Thank you. I really actually don't play very many games at all I just
like doing these things because I always find that I learn much about
the OS this way =] really. But I actually want to launch the same
program with root access, is there a special way to do this? As far as
I know I can't launch two instances of my same program so how would I
go about doing this?

Mitch

On Jan 28, 2008 9:59 PM, Kyle Sluder <email@hidden> wrote:
> On Jan 29, 2008 12:07 AM, Mitchell Hashimoto <email@hidden> wrote:
> >         NSString *fullPath = @"/Applications/Program.app/Contents/MacOS/Program";
>
> This seems odd.  Is Program.app a separate application from your own
> (e.g. you're building a launcher to an existing, but separate, app)?
> If so, use NSWorkspace to get the path to the application you want.
> The Most Correct Way(TM) to do this would be -[NSWorkspace
> absolutePathForAppBundleWithIdentifier] (which you would pass the
> app's bundle identifier, a string in the form
> com.yourcompany.AppName), but -[NSWorkspace fullPathForApplication:]
> may suit you just fine (in which case you would pass "AppName", that
> is the app bundle's name without the extension).
>
> Once you have the path to the bundle, use NSBundle to get the path to
> the actual executable inside the bundle and append it to the string
> you got above.  This is the path you pass to Authorization Services.
>
> >         AuthorizationItem myItems[1];
> >
> >         myItems[0].name = kAuthorizationRightExecute;
> >         myItems[0].valueLength = [fullPath length];
> >         myItems[0].value = [fullPath cStringUsingEncoding:NSASCIIStringEncoding];
> >         myItems[0].flags = 0;
>
> Your use of -[NSString length] and -[NSString cStringUsingEncoding:]
> is troublesome.  NSString has an instance method specifically for what
> you're trying to do: -fileSystemRepresentation.  It returns a C string
> that's appropriate to be passed to the filesystem, regardless of funky
> Unicode characters in paths.  You can use the C strlen() function to
> get the length of a C string (don't use -[NSString length] for this;
> it may not match up).
>
> HTH, and remember to use your powers for good, not evil.  Cheaters
> just ruin the fun for the rest of us.
>
> --Kyle Sluder
>
_______________________________________________

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: Running process as root from Cocoa
      • From: "Kyle Sluder" <email@hidden>
References: 
 >Running process as root from Cocoa (From: "Mitchell Hashimoto" <email@hidden>)
 >Re: Running process as root from Cocoa (From: Nir Soffer <email@hidden>)
 >Re: Running process as root from Cocoa (From: Bill Bumgarner <email@hidden>)
 >Re: Running process as root from Cocoa (From: "Mitchell Hashimoto" <email@hidden>)
 >Re: Running process as root from Cocoa (From: "Kyle Sluder" <email@hidden>)

  • Prev by Date: Re: Running process as root from Cocoa
  • Next by Date: Re: Running process as root from Cocoa
  • Previous by thread: Re: Running process as root from Cocoa
  • Next by thread: Re: Running process as root from Cocoa
  • Index(es):
    • Date
    • Thread