在不提示用户的情况下删除 SSL 证书

Delete SSL Certificate without prompting the user

我已经编写了一些代码行,如果该证书已经存在,它们将在安装新证书之前从证书存储中删除证书,如下所示:

X509Store store = new X509Store(StoreName.Root, StoreLocation.CurrentUser);
            store.Open(OpenFlags.ReadWrite | OpenFlags.IncludeArchived);
            X509Certificate2Collection certs = store.Certificates.Find(X509FindType.FindBySubjectName, "CertName", false);

            if (certs.Count > 0)
            {
                foreach (var cert in certs)
                {
                    store.Remove(cert);
                }
}

但是,每次在删除之前检测到证书时,它都会提示用户按是,以便删除证书。是否可以在不询问用户的情况下删除证书?

Is it possible to delete the certs without asking the user?

简短的回答是否定的。 Current User\Trusted Root CAs 中的证书管理(add/remove 证书)需要明确的用户同意。此行为在 crypt32.dll 库中进行了硬编码。