Exemple d’extraction de certificat d’ordinateur
L’exemple suivant montre comment récupérer la collection de certificats de l’ordinateur :
HRESULT GetMachineCert( BYTE **ppbCert, DWORD *pcbCert )
{
HRESULT hr = S_OK;
IWMDRMProvider *pProvider = NULL;
IWMDRMSecurity *pSecurity = NULL;
BYTE rgbVersion[4];
// Create a provider object.
hr = WMDRMCreateProvider( &pProvider );
if( FAILED( hr ) ) goto EXIT;
// Create a security object from a provider object.
hr = pProvider->CreateObject( IID_IWMDRMSecurity, (void**) &pSecurity );
if( FAILED( hr ) ) goto EXIT;
// Query the security to get the machine certificate.
hr = pSecurity->GetMachineCertificate( WMDRM_CERTIFICATE_TYPE_V2,
rgbVersion, ppbCert, pcbCert );
if( FAILED( hr ) ) goto EXIT;
EXIT:
SAFE_RELEASE( pSecurity );
SAFE_RELEASE( pProvider );
return hr;
}