Quite right, “Activate_Now” is the name of my own function. Your function was TA_CheckAndSavePKey(), so you have correctly identified where the problem is: we have a product key that has been assigned to this user, but for some reason TA_CheckAndSavePKey() refuses to accept it, returning TA_E_ALREADY_ACTIVATED (and this form's insistance on replacing my text with italics every time I type underscore is VERY annoying).
The code follows. USER_DATA is a structure of my own that recovers data stored in the registry by a previous dialog. The exact structure is not important, but it includes the product key assigned to this user.
The problem is that TA_CheckAndSavePKey() returns TA_E_ALREADY_ACTIVATED, and then I believe TA_Deactivate() returns a fail (I'll get the client to confirm that it still happens: I'm having two conversations here). My question remains: how do I diagnose this condition with certainty (e.g. by naming the conflicting product key) or, how do I zap all activations of our product on this PC.
BOOL
Activate_Now(void)
{
HRESULT hr;
PUSER_DATA pud = UserData_Get();
if (!taHandle) {
SetDatFilePath();
taHandle = TA_GetHandle(Tx_GUID);
}
_check_again:
hr = TA_CheckAndSavePKey(taHandle,pud->product_key, TA_USER); // we use the TA_USER flag so we don't need elevated permissions.
if (hr == TA_OK) {
// Message("Product key saved successfully.");
// try to activate
hr = TA_Activate(taHandle,NULL);
if (hr == TA_OK) {
Message("Activate was successful!");
bActivated = TestTimeLimit();
} else {
Error("Activation failed!", hr);
return FALSE;
}
} else if (hr==TA_E_ALREADY_ACTIVATED) {
if (MessageBox(GetFocus(),"Strange. Activation is failing because the server says that "szAppName" is already activated on this PC.\nWould you like to force deactivation and try again?","Activation Error",MB_ICONINFORMATION|MB_YESNO)==IDYES) {
hr = TA_Deactivate(taHandle,1);
if (hr==TA_OK) {
MessageBox(GetFocus(),"Done. This PC should now be deactivated. Click \"OK\" to attempt activation again.","Activation Progress",MB_ICONINFORMATION|MB_OK);
goto _check_again;
} else {
Error("Deactivation did not work. I'm going to have to bail here.", hr);
return FALSE;
}
}
} else {
Error("Software error: Could not write product key.", hr);
return FALSE;
}
return TRUE;
}