다음을 통해 공유


Active Directory 저장소 열기 및 인증서 검색

[CAPICOM은 Windows Server 2008, Windows Vista 및 Windows XP 운영 체제에서 사용할 수 있는 32비트 전용 구성 요소입니다. 대신 .NET Framework 사용하여 보안 기능을 구현합니다. 자세한 내용은 CAPICOM 사용에 대한 대안을 참조하세요.]

도메인 사용자의 인증서 가 저장된 Active Directory 저장소에서 인증서를 검색할 수 있습니다. Active Directory 저장소는 읽기 전용 모드에서만 열 수 있으며 애플리케이션은 CAPICOM을 사용하여 Active Directory 저장소에서 인증서를 추가하거나 제거할 수 없습니다.

CAPICOM 오류에서 Err.Number 의 음수 10진수 값이 반환됩니다. 자세한 내용은 CAPICOM_ERROR_CODE 참조하세요. Err.Number의 양의 10진수 값에 대한 자세한 내용은 Winerror.h를 참조하세요.

다음 예제에서는 Active Directory 저장소를 열고 해당 저장소에서 인증서를 검색하는 방법을 보여 줍니다.

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