Previous page

Next page

Locate page in Contents

Managing Licenses

The Parallels license information can be retrieved using the PrlSrv_GetLicenseInfo function. The function returns a handle of type PHT_LICENSE containing the license details. The handle provides a set of functions to retrieve the details. To install or update a license, use the PrlSrv_UpdateLicense function.

The following sample function demonstrates how to obtain license information and how to install a new license.

PRL_RESULT UpdateLicenseSample(PRL_HANDLE hServer)

{

PRL_HANDLE hJob = PRL_INVALID_HANDLE;

PRL_HANDLE hJobResult = PRL_INVALID_HANDLE;

PRL_HANDLE hLicense = PRL_INVALID_HANDLE;

PRL_HANDLE hUpdateLicense = PRL_INVALID_HANDLE;

PRL_RESULT ret = PRL_ERR_UNINITIALIZED;

PRL_RESULT nJobReturnCode = PRL_ERR_UNINITIALIZED;

// Get the license info from the Parallels Service.

hJob = PrlSrv_GetLicenseInfo(hServer);

// Wait for the job to complete.

ret = PrlJob_Wait(hJob, 1000);

if (PRL_FAILED(ret))

{

// Handle the error...

return -1;

}

// Analyze the result of PrlSrv_GetUserInfoList.

ret = PrlJob_GetRetCode(hJob, &nJobReturnCode);

if (PRL_FAILED(ret))

{

// Handle the error...

PrlHandle_Free(hJob);

return -1;

}

// Check the job return code.

if (PRL_FAILED(nJobReturnCode))

{

// Handle the error...

PrlHandle_Free(hJob);

return -1;

}

// Get job result.

ret = PrlJob_GetResult(hJob, &hJobResult);

PrlHandle_Free(hJob);

if (PRL_FAILED(ret))

{

// Handle the error...

return -1;

}

// Get parameter from job result.

ret = PrlResult_GetParam(hJobResult, &hLicense);

PrlHandle_Free(hJobResult);

if (PRL_FAILED(ret))

{

// Handle the error...

return -1;

}

// Get company name.

PRL_CHAR sCompany[1024];

PRL_UINT32 nCompanyBufSize = sizeof(sCompany);

ret = PrlLic_GetCompanyName(hLicense, sCompany, &nCompanyBufSize);

if (PRL_FAILED(ret))

{

// Handle the error...

PrlHandle_Free(hLicense);

return -1;

}

printf("Company: %s\n", sCompany);

// Get user name.

PRL_CHAR sUser[1024];

PRL_UINT32 nUserBufSize = sizeof(sUser);

ret = PrlLic_GetUserName(hLicense, sUser, &nUserBufSize);

if (PRL_FAILED(ret))

{

// Handle the error...

PrlHandle_Free(hLicense);

return -1;

}

printf("User: %s\n", sUser);

// Get license key.

PRL_CHAR sKey[1024];

PRL_UINT32 nKeyBufSize = sizeof(sKey);

ret = PrlLic_GetLicenseKey(hLicense, sKey, &nKeyBufSize);

if (PRL_FAILED(ret))

{

// Handle the error...

PrlHandle_Free(hLicense);

return -1;

}

printf("Key: %s\n", sKey);

// See license type.

PRL_BOOL isTrial = PRL_TRUE;

ret = PrlLic_IsTrial(hLicense, &isTrial);

if (PRL_FAILED(ret))

{

// Handle the error...

PrlHandle_Free(hLicense);

return -1;

}

printf("Trial: %d\n", isTrial);

PrlHandle_Free(hLicense);

// Update the license info.

// Here, we use the same license information that we

// retrieved earlier. Normally, you would use the

// information that you received from

// your Parallels product distributor.

hUpdateLicense = PrlSrv_UpdateLicense(hServer, sKey,

sUser, sCompany);

// Wait for the job to complete.

ret = PrlJob_Wait(hUpdateLicense, 1000);

if (PRL_FAILED(ret))

{

// Handle the error...

return -1;

}

PrlHandle_Free(hUpdateLicense);

}