Elevate privileges for install


Hi all,

this isn’t really Juce specific but maybe someone can help.

I’m building an installer which also might wan’t to install something into /Library or /Applications. To do this I use the following code to obtain admin privileges :

  AuthorizationRef authRef;
  char rightName[] = "system.install.root.user";
  AuthorizationItem kActionRight = { rightName, 0, 0, 0 };
  AuthorizationRights rights = {1, &kActionRight};
  AuthorizationFlags flags = kAuthorizationFlagExtendRights | kAuthorizationFlagInteractionAllowed;		
  OSStatus err = AuthorizationCreate(&rights, 0, flags, &authRef);

This works fine if the installing user is an admin. If run from a standard user it doesn’t work although no error is given (err == noErr). It does reques the user/pw from an admin account and won’t accept the standard users’ account. Installers made with PackageMaker request the same right but also do work when run from a standard user.

The installer is a web-based installer, so Packagemaker isn’t an option.

Does anyone know what I might do wrong or how this could be accomplished?
The installer should also work on 10.5.

Thanks for any help,


I found a workaround by using command line tools (mv, mkdir, rm…) via AuthorizationExecuteWithPrivileges(). This makes it quite unhandy as the Juce file copy/delete etc. functions can’t be used. Also AuthorizationExecuteWithPrivileges() is marked deprecated so it might not work in 10.8 any more. Hopefully I will find a better alternative until then. :slight_smile:



You were right - it doesn’t work for 10.8 :frowning: Any other workaround?


Can’t you just use AppleScript?
Something like


[quote=“vishvesh”]Can’t you just use AppleScript?
Something like

Thanks for the information. I’m currently busy with other stuff but I will try that.



Sure. It should work. I had tried something similar from IzPack installer!