CheckAndSavePKeySolved

Some of our users failed to activate product key and I think because the CheckAndSavePKey(key, TA_SYSTEM) failed due to non-admin level call. I use NSIS to create an installer and do not know how to call CheckAndSavePKey(0, TA_SYSTEM) to setup for subsequent call.

You don't need to call CheckAndSavePKey() with a null product key if you have a product key available.

More information is needed to know what is going on. Likely the customer is either using the key on more computers than they're licensed for, or they're blocking the activation servers. But that's just a guess. Much more information is needed to give you any useful help.

Also, make sure you're using the latest version of TurboActivate, currently 4.0.9.3.

On my computer, I can activate using the customer's key, so the key is OK.How do you find out what is going on? Quote from turboactivate.h :"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."So, I just follow this recommendation and call CheckAndSavePKey (0, TA_SYSTEM) in the NSIS installer. By the way I now know how to call dll in NSIS.

Our user still having problem activating after I added CheckAndSavePKey(0, TA_SYSTEM); to the NSIS installer!!!This is very urgent, so please help! Why do I have to worry about TA_SYSTEM or TA_USER? You should handle all the details, your API should not require me to specify these flags.

More information is needed to know what is going on. What error are you getting? Code snippets are needed with return codes.

>> "Why do I have to worry about TA_SYSTEM or TA_USER? You should handle all the details, your API should not require me to specify these flags."

Our API does handle all the details. The flags give you options. Different customers want different behavior. We handle that (like any API handles that) by offering functions and parameters to said functions.

CheckAndSavePKey(keyStr, TA_SYSTEM); and CheckAndSavePKey(keyStr, TA_USER); all returned 1

void ASAPI License::licenseActivate(ac_itemRef item, ac_notifierRef notifier){ if (isTurboActivateChecked == false) return; USES_CONVERSION;

ac_int32 length; char data[LICENSING_MESS_SIZE]; //long answer = 0; std::string aKeyStr; LPWSTR keyStr; HRESULT hr; ac_itemRef info = sACDialog->GetItem(g->licenseDlg, kLicenseMessText); ac_itemRef xfer = sACDialog->GetItem(g->licenseDlg, kExportLicenseButton); ac_itemRef buy = sACDialog->GetItem(g->licenseDlg, kLicensePurchaseButton); ac_itemRef key = sACDialog->GetItem(g->licenseDlg, kActivateKeyItem); sACMenuItem->SetText(xfer, "Transfer"); sACMenuItem->SetTipString(xfer, LICENSING_TRANSFER_TIP);

length = sACMenuItem->GetTextLength(key); sACMenuItem->GetText(key, data, length); aKeyStr.assign(data, length); if (length == LICENSE_ACTIVATION_KEY_LENGTH && aKeyStr.find ("-" , 1) != string::npos ) { keyStr = A2W(aKeyStr.c_str());

hr = CheckAndSavePKey(keyStr, TA_SYSTEM); //got 1A if (hr == TA_OK) {//licenseValidated ip_license_support = License::checkAndActivateKey(true); } else { acErrorAlert("License: Failed TA_SYSTEM code "+ Gcodes::tostr(hr, 0) + ", checking TA_USER..."); hr = CheckAndSavePKey(keyStr, TA_USER); if (hr == TA_OK) {//licenseValidated ip_license_support = License::checkAndActivateKey(true); } else { acErrorAlert("License: Failed TA_USER code " + Gcodes::tostr(hr, 0) + ", aborting..."); ip_license_support = ip_none; } } } else {//maybe reactivation? ip_license_support = License::checkAndActivateKey(true); } if (ip_license_support != ip_none) { sACMenuItem->SetText(key, aKeyStr.c_str()); sACMenuItem->SetText(buy, "Visit Us"); sACMenuItem->Enable(xfer, true); sACMenuItem->Enable(item, false); } LicensePrintSupportText(ip_license_support, ip_license_support != ip_none);}

OK, you're using C/C++ rather than NSIS, so that makes things easier (because you can actually debug C/C++ code.

My guess is that your A2W() function isn't working correctly. Either you're not getting a UTF-16 string out the other side, or it's corrupted. But it's an easy test. Just run it in your debugger and put a breakpoint there. You can see whether the keyStr data is valid.

The keyStr is correct. As mentioned previously?: "On my computer, I can activate using the customer's key, so the key is OK."This happens, currently, only to one user where his trial ran out. His purchased key works on my computer but not his.

OK, can you add some logging to your code logging the following:

1. Passed in arguments to any TurboActivate function you call.

2. Return codes for any function you call.

Also, make sure you're using the latest version of TurboActivate (4.0.9.4). From the fact that you're using TA 3.x function calls it suggests you might be using an old versions of TurboActivate.

I download the latest version 2 weeks ago. How do I find out which version I have?When user clicked the Activate button, I call License::licenseActivate which call CheckAndSavePKey and that is all, no other calls are made because CheckAndSavePKey returned TA_FAIL.

"From the fact that you're using TA 3.x function calls it suggests you might be using an old versions of TurboActivate."Which call is from TA 3.x?

Make sure you've included the latest TurboActivate.h file and linking against the latest TurboActivate.lib. Also, you can tell the TurboActivate.dll version by right clicking it, clicking properties, Details, and you'll see the version.

The TurboActivate.h has no version inside it! Am I to check for the date?I downloaded the static lib and it also has no version, how can you tell???If I use the static libs do I also need the file TurboActivate.dll?

>> "The TurboActivate.h has no version inside it! Am I to check for the date?"

Yes, or always copy the latest version when you get the latest version of TurboActivate.

>> "I downloaded the static lib and it also has no version, how can you tell???"

Static libraries cannot contain meta-data. There's no way to "embed" the version. Just store them in a folder with the version in it.

>> "If I use the static libs do I also need the file TurboActivate.dll?"

Nope, that's the point of the static libraries, you don't need to use the dynamic library.

We are using the latest TurboActivate and the same error occurred (TA_FAIL). TA_FAIL is too general to debug a failure!

Very urgent, anymore ideas?

You need to give us more information. See our previous posts: https://wyday.com/forum/t/3647/checkandsavepkey/#post-17635

It's probably an error in your conversion function. It's just a guess. Give us more info and we'll be able to help you. Otherwise you're flying blind.

Specifically, what do you want to know?

"OK, can you add some logging to your code logging the following:

1. Passed in arguments to any TurboActivate function you call.

2. Return codes for any function you call."

As stated before, only CheckAndSavePKey is called with a TA_FAIL return code. You should help us log the events that lead to the failure during and after CheckAndSavePKey is called.

We're asking you to give us a log of what you're passing to TurboActivate functions. You gave us just the return codes. That's good, but only half the story. What you're passing to the functions is equally important. Without it we can't help you.

I did at the beginning. Here it is again:

CheckAndSavePKey(key, TA_SYSTEM) return TA_FAIL on one user system but return TA_OK on my system.

The customer that is encountering the error: output to a text file the data that you're passing into TA_CheckAndSavePkey(). Yes, the code is useful, but again, the information we need to actually help you is the actual data.

Like we've said: the problem is likely in your ASCII to WideChar conversion function. It's likely failing and/or returning corrupted data. And when you pass invalid key or corrupt data to TA_CheckAndSavePKey() it tells you as much by saying TA_FAIL (i.e. the product key is invalid).

Hence needing the actual data.

If you're encountering this error on your own machine, the process is a whole lot simpler. Attach a debugger to your app, step through, and see what the "keyStr" contains. Make sure it's a proper "double-wide char" string that is null terminated and make sure the data is actually a product key and not garbage.

I hard-coded the key and it still failed with TA_FAIL:

hr = CheckAndSavePKey(L"the user key", TA_SYSTEM);

What else would you like to know?

1. Use the latest TurboActivate API and the latest TurboActivate version (you're still using old API calls).

2. Realize that using old versions of the API will give old-style return codes. For example, prior to version TA 4.0, if you used CheckAndSavePKey() on a computer where there was already a product key activated, then you would get TA_FAIL. In TA 4.0 and newer, in that exact case, you now get TA_E_ALREADY_ACTIVATED.

I am using the latest TurboActive already. Which call is from previous version, prior to 4?User machine never got activated but his trial expired, so this is the first time he tries to activate.

hr = CheckAndSavePKey(L"the user key", TA_SYSTEM);

is a TurboActivate 3.x and prior call.

hr = TA_CheckAndSavePKey(handle, L"the user key", TA_SYSTEM);

is a TurboActivate 4.0 and newer call.

Thanks, it worked with the newer version.