Search code examples
c#powershellx509certificatewindows-server-2008-r2

How to remove a certificate Store added by makecert


Using the -ss option of Microsoft tool MakeCert.exe (-ss specifies the subject's certificate store name that stores the output certificate), I create my own store on a server. I'am able to remove my certificate programaticaly, but I'am not able to remove the store itself. According to the error message this not seems to be supported by the provider.

I can't even use the MMC snapin (certmgr.msc) to remove it. Does anybody know how to do that ?

PS cert:\LocalMachine> Remove-Item .\SigningStore
Remove-Item : L'exécution du fournisseur s'est arrêtée, car le fournisseur ne prend pas en charge cette opération.
Au niveau de ligne : 1 Caractère : 12
+ Remove-Item <<<<  .\SigningStore
    + CategoryInfo          : NotImplemented: (:) [Remove-Item], PSNotSupportedException
    + FullyQualifiedErrorId : NotSupported,Microsoft.PowerShell.Commands.RemoveItemCommand

The only way I found was to use CertUnregisterSystemStore Win32 API


Solution

  • Read this and add-type with c# code with pinvoke (already done!) of crypt32.dll