Admin privileges

I noticed in the TurboActivate C sample code for Windows that it says "calling [CheckAndSavePKey] using the TA_SYSTEM flag (the first time only) requires system-admin privileges". How do I get system-admin privileges?

I assume that what I want to do is what most users would want to do, namely:1. Create an installer with InnoSetup or something similar2. NOT have the installer integrated with TurboActivate at all -- just have it copy files into C:\ProgramFiles\MyAppFolder3. Let the user run application as a the trial version for several days4. Allow them to enter the product key into the application before the trial expires

So I guess I'm just unclear as to how to obtain system-admin privileges so that step 4 will be successful.

Thanks!

We go into detail in the TurboActivate.h file:

   Checks and saves the product key.




   Note: If you pass in the TA_SYSTEM flag and you don't have "admin" or "elevated"   permission then the call will fail.


   If you call this function once in the past with the flag TA_SYSTEM and the calling   process was an admin process then subsequent calls with the TA_SYSTEM flag will   succeed even if the calling process is *not* admin/elevated.


   If you want to take advantage of this behavior from an admin process   (e.g. an installer) but the user hasn't entered a product key then you can   call this function with a null string:


            CheckAndSavePKey(0, TA_SYSTEM);


   This will set everything up so that subsequent calls with the TA_SYSTEM flag will   succeed even if from non-admin processes.




   Returns: TA_OK on success. Handle all other return codes as failures.


   Possible return codes: TA_OK, TA_FAIL, TA_E_PDETS, TA_E_PERMISSION,                          TA_E_INVALID_FLAGS
How do I get system-admin privileges?

On Windows just run the exe "elevated" on Vista+ or under an admin account on Windows XP. On Linux run the app with "sudo" or "su". Ditto for Mac OS X.

The easiest way to handle this, as described in the TurboActivate.h comment on the function, is to call the CheckAndSavePKey(0, TA_SYSTEM); function in your installer that you'll know will be elevated. Then you can make all subsequent calls from non-elevated apps.

Does that make sense?

Yes, makes sense. I didn't think to look in the TurboActivate.h file. Thanks.

Are there any help documents for setting up TurboActivate with an OS X installation (i.e., PackageMaker) to get the admin privileges? I can only find Windows examples (Inno/NSIS).

The first thing you should do, if you're using PackageMaker, is to set the "Require Admin Authorization" checkbox. See: Component Package Configuration Pane (http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/PackageMakerUserGuide/Workflow/Workflow.html#//apple_ref/doc/uid/TP40005371-CH1000-SW21 ).

From there you have a few options. The easiest thing to do is to execute a script or executable after your app installs. And from this script call the "CheckAndSavePKey(0, TA_SYSTEM);" function. See: Component Package Scripts Pane (http://developer.apple.com/library/mac/#documentation/DeveloperTools/Conceptual/PackageMakerUserGuide/Workflow/Workflow.html#//apple_ref/doc/uid/TP40005371-CH1000-SW29 ).

Another option is to develop a plugin for your PackageMaker installer. Here's an Installer Plugin sample with code. (http://developer.apple.com/library/mac/#samplecode/InstallerPluginSample/Introduction/Intro.html#//apple_ref/doc/uid/DTS10003945-Intro-DontLinkElementID_2 )

Does that make sense? (Sorry I couldn't make the links clickable -- this damn forum software).

Makes sense. I'll give the easy option a try first. 🙂

Ok, I think I've got the script running properly, but I just want to verify one thing. When I call CheckAndSavePKey(0, TA_SYSTEM) from the script, it returns TA_E_PKEY. Does this indicate that the admin rights were successfully applied for subsequent calls? And would it return something different if the admin rights were not successfully applied?

I've activated/deactivated so many times now, I need a reality check 🙂.

Thanks for your help.

Does this indicate that the admin rights were successfully applied for subsequent calls?

Correct. It's returning TA_E_PKEY because a null pkey is invalid.

And would it return something different if the admin rights were not successfully applied?

Yes, TA_FAIL or TA_E_PERMISSION will signify the "TA_SYSTEM" stuff failed to get set up. Of course, all the return codes are listed in TurboActivate.h file:

   Possible return codes: TA_OK, TA_FAIL, TA_E_PDETS, TA_E_PERMISSION,                          TA_E_INVALID_FLAGS

Ok so then I guess what I need to know is, how to I "get rid" of the admin privileges, so I can test a fresh installation? Just calling Deactivate() doesn't seem to do it.

In other words, I want the call to CheckAndSavePKey(0, TA_SYSTEM) to not return TA_E_PKEY any more -- I want it to return TA_FAIL or TA_E_PERMISSION. But I can't seem to get back there.

There's no way to "undo" TA_SYSTEM setup. And because deactivating is part of the normal user-flow, deactivating won't undo it either.

To re-test this behavior you can run Mac in a Virtual Machine and test it there. Or you can create another product in LimeLM. The Virtual Machine route is easier.

Hi there, I'm encountering a strange new issue. I've recently noticed that when I call CheckAndSavePKey from Inno Setup (using your example code from http://wyday.com/limelm/help/using-turboactivate-with-inno-setup/), it returns TA_FAIL. I think it used to return TA_OK (when I originally posted this topic), so I'm not sure what's changed.

Specifically, I'm calling CheckAndSavePKey('', 1) -- that is, with no product key. It returns TA_FAIL even when I run the installer in a virtual machine with a fresh Windows install.

Is this expected? I am using TA 3.4.6.

Specifically, I'm calling CheckAndSavePKey('', 1) -- that is, with no product key. It returns TA_FAIL even when I run the installer in a virtual machine with a fresh Windows install.

Is this expected? I am using TA 3.4.6.

Yes, this is expected. you're passing an empty string (which is not a valid product key). So it will return TA_FAIL. However, because TA_E_PERMISSION is not returned you know that the system files were created successfully.

It would never return TA_OK (because a null or empty string is not a valid product key).

Ok great, thanks very much. That definitely clears it up.