Compartir a través de


Apertura del almacén de Active Directory y recuperación de certificados

[CAPICOM es un componente solo de 32 bits que está disponible para su uso en los siguientes sistemas operativos: Windows Server 2008, Windows Vista y Windows XP. En su lugar, use .NET Framework para implementar características de seguridad. Para obtener más información, vea Alternativas al uso de CAPICOM.

Los certificados se pueden recuperar de un almacén de Active Directory donde se almacenan los certificados de los usuarios de un dominio. Un almacén de Active Directory solo se puede abrir en el modo de solo lectura y las aplicaciones no pueden agregar ni quitar certificados de un almacén de Active Directory mediante CAPICOM.

En cualquier error CAPICOM, se devuelve un valor decimal negativo de Err.Number . Para obtener más información, consulte CAPICOM_ERROR_CODE. Para obtener información sobre los valores decimales positivos de Err.Number, consulte Winerror.h.

En el ejemplo siguiente se muestra cómo abrir un almacén de Active Directory y recuperar certificados de ese almacén.

Sub OpenADStore()
        On Error GoTo ErrorHandler
        Dim mystore As Store
        Set mystore = New Store
        
        ' Put a string that represents the name of a certificate 
        ' subject in SubjectNameCn. In the following example, 
        ' the * wildcard character is used in the string so that
        ' the Active Directory store will be searched for all 
        ' certificates with a subject name beginning with 'S.'
       
        Dim SubjectNameCn As String
        ' The following uses 'cn=' and the * wildcard character.
        ' Using this string, all certificates in the Active Directory
        ' store with a subject name beginning with an 'S' would
        ' be returned.

        SubjectNameCn = "CN=S*"
        
        ' Active Directory stores can only be opened with read-only
        ' access.
        
         mystore.Open CAPICOM_ACTIVE_DIRECTORY_USER_STORE, _
              SubjectNameCn, CAPICOM_STORE_OPEN_READ_ONLY
        
        If mystore.Certificates.Count < 1 Then
               MsgBox "A certificate for " & SubjectNameCn & _
                      " was not found "
        Else
               MsgBox "The certificate has been retrieved."
        End If
        
        Set mystore = Nothing
        Exit Sub

ErrorHandler:
         
         If Err.Number > 0 Then
               MsgBox "Visual Basic error found:" & Err.Description
         Else
               MsgBox "CAPICOM error found : " & Err.Number
         End If
End Sub