Platform SDK: Certificate Enrollment Control

Request Sample in Visual Basic

The following Visual Basic sample code shows how the Certificate Enrollment Control can be used with the CCertRequest object to create and submit a certificate request. The CCertRequest object is available in the Certcli Type Library.

Private Sub Command1_Click()

    ' Declare objects for Enrollment and Request controls.
    Dim objXen As Object
    Dim objRequest As CCertRequest ' from CertCli Type library
    
    ' string variables
    Dim strDN As String
    Dim strReq As String
    
    ' variable to retrieve request's Submit disposition
    Dim nDisp As Long
        
    ' consts used by CCertRequest
    Const CR_IN_BASE64 As Long = &H1
    Const CR_IN_PKCS10 As Long = &H100
    
    On Error GoTo Err_Handler
    
    ' Create an instance of the Certificate Enrollment object.
    Set objXen = CreateObject("CEnroll.CEnroll.1")
    
    ' Create an instance of the Certificate Request object.
    Set objRequest = New CCertRequest

    'Build the distinguished name string.
    strDN = "CN=UserName" _
             & ",OU=UserUnit" _
             & ",O=UserOrg" _
             & ",L=UserCity" _
             & ",S=WA" _
             & ",C=US"

    ' Create the PKCS #10 request.
    strReq = objXen.createPKCS10(strDN, "1.3.6.1.4.1.311.2.1.21")

    ' Submit the request.
    MsgBox ("Attempting request submit")
    nDisp = objRequest.Submit(CR_IN_BASE64 Or CR_IN_PKCS10, _
                               strReq, _
                               "", _
                               "Server\CertAuth")

    ' Free the objects.
    Set objXen = Nothing
    Set objRequest = Nothing

    Exit Sub

Err_Handler:

    ' Inform user there was an error.
    MsgBox ("Failed")
    ' Disable error handling.
    On Error GoTo 0

End Sub