Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not work!
Lazarus - macOS - Request Admin Authentication
October 24, 2019 11:36 PM
Sometimes one needs to verify if the user is admin and has the appropriate right to access a certain function.
there are under macOS several ways to do this, but to use the proper API call in Lazarus Pascal, you can try this function I created.
It triggers a Admin authentication request and returns either TRUE or FALSE.
Uses ... MacOSAll ...
authItem.flags := 0;
authItem.name := kAuthorizationRightExecute;
authItem.value := nil;
authRights.count := 1;
authRights.items := @authItem;
authRef := nil;
authFlags := kAuthorizationFlagInteractionAllowed or kAuthorizationFlagExtendRights or kAuthorizationFlagPreAuthorize;
status := AuthorizationCreate(@authRights, kAuthorizationEmptyEnvironment, authFlags, authRef);
Result := status=errAuthorizationSuccess;