Example #1
0
        public unsafe static IEnumerable <PhysicalStoreInformation> EnumeratePhysicalStores(SystemStoreLocation location, string systemStoreName)
        {
            var      info       = new List <PhysicalStoreInformation>();
            GCHandle infoHandle = GCHandle.Alloc(info);

            fixed(char *namePointer = systemStoreName)
            {
                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 CertEnumPhysicalStoreCallback(PhysicalStoreEnumeratorCallback);
                    Direct.CertEnumPhysicalStore(
                        pvSystemStore: (IntPtr)namePointer,
                        dwFlags: (uint)location,
                        pvArg: GCHandle.ToIntPtr(infoHandle),
                        pfnEnum: callBack);
                }
                finally
                {
                    infoHandle.Free();
                }
            }

            return(info);
        }