public unsafe static IEnumerable <SystemStoreInformation> EnumerateSystemStores(SystemStoreLocation location, string name = null) { var info = new List <SystemStoreInformation>(); GCHandle infoHandle = GCHandle.Alloc(info); fixed(char *namePointer = string.IsNullOrEmpty(name)?null : name) { try { // To lookup system stores in an alternate location you need to set CERT_SYSTEM_STORE_RELOCATE_FLAG // and pass in the name and alternate location (HKEY) in pvSystemStoreLocationPara. var callBack = new CertEnumSystemStoreCallback(SystemStoreEnumeratorCallback); Direct.CertEnumSystemStore( dwFlags: (uint)location, pvSystemStoreLocationPara: (IntPtr)namePointer, pvArg: GCHandle.ToIntPtr(infoHandle), pfnEnum: callBack); } finally { infoHandle.Free(); } } return(info); }