IX509Enrollment2::InitializeFromTemplate method (certenroll.h)

The InitializeFromTemplate method initializes the enrollment object by using a template.


HRESULT InitializeFromTemplate(
  X509CertificateEnrollmentContext context,
  IX509EnrollmentPolicyServer      *pPolicyServer,
  IX509CertificateTemplate         *pTemplate



An X509CertificateEnrollmentContext enumeration value that indicates whether the requested enrollment is for a user, a computer, or an administrator acting on behalf of a computer. This can be one of the following values.

Value Meaning
The certificate is being requested for an end user.
The certificate is being requested for a computer.
The certificate is being requested by an administrator acting on the behalf of a computer.


Pointer to an IX509EnrollmentPolicyServer object that represents the certificate enrollment policy (CEP) server that contains the template specified by the pTemplate parameter.


Pointer to an IX509CertificateTemplate object that represents the template to use during initialization.

Return value

If the function succeeds, the function returns S_OK.

If the function fails, it returns an HRESULT value that indicates the error. Possible values include, but are not limited to, those in the following table. For a list of common error codes, see Common HRESULT Values.

Return code/value Description
The pPolicyServer and pTemplate parameters cannot be NULL.
The enrollment object has already been initialized.


The InitializeFromTemplate method:

  • Examines the template to determine the type of request needed.
  • Creates the appropriate type of request object (PKCS #10, PKCS #7, or CMC).
  • Sets the following properties on the request if values currently exist:
  • Initializes the request object by using the template.
  • Retrieves the signature count, issuance policies, and application policies from the template.


Minimum supported client Windows 7 [desktop apps only]
Minimum supported server Windows Server 2008 R2 [desktop apps only]
Target Platform Windows
Header certenroll.h

See also