@@ -701,6 +701,10 @@ static HRESULT FindExistingCertificate(
701701 PCCERT_CONTEXT pCertContext = NULL ;
702702 BYTE* pbCertificate = NULL ;
703703 DWORD cbCertificate = 0 ;
704+ LPWSTR pwzUniquePrefix = NULL ;
705+
706+ hr = StrAllocFormatted (&pwzUniquePrefix, L" %s_wixCert_" , wzName);
707+ ExitOnFailure (hr, " Failed to format unique name" );
704708
705709 hCertStore = ::CertOpenStore (CERT_STORE_PROV_SYSTEM, 0 , NULL , dwStoreLocation | CERT_STORE_READONLY_FLAG, wzStore);
706710 MessageExitOnNullWithLastError (hCertStore, hr, msierrCERTFailedOpen, " Failed to open certificate store." );
@@ -713,7 +717,7 @@ static HRESULT FindExistingCertificate(
713717 DWORD cbFriendlyName = sizeof (wzFriendlyName);
714718
715719 if (::CertGetCertificateContextProperty (pCertContext, CERT_FRIENDLY_NAME_PROP_ID, reinterpret_cast <BYTE*>(wzFriendlyName), &cbFriendlyName) &&
716- CSTR_EQUAL == ::CompareStringW (LOCALE_SYSTEM_DEFAULT, 0 , wzName , -1 , wzFriendlyName, -1 ))
720+ CSTR_EQUAL == ::CompareStringW (LOCALE_SYSTEM_DEFAULT, 0 , pwzUniquePrefix , -1 , wzFriendlyName, -1 ))
717721 {
718722 // If the certificate with matching friendly name is valid, let's use that.
719723 long lVerify = ::CertVerifyTimeValidity (NULL , pCertContext->pCertInfo );
@@ -739,6 +743,7 @@ static HRESULT FindExistingCertificate(
739743 pbCertificate = NULL ;
740744
741745LExit:
746+ ReleaseStr (pwzUniquePrefix);
742747 ReleaseMem (pbCertificate);
743748
744749 if (pCertContext)
0 commit comments