none
Help with enumerating certs from X509Store RRS feed

  • Question

  • I am writing a winform app that will list all the certs from LocalMachine/My store in a list box.  When I run the MMC cert store snapin for my box (Windows 2012) I can see 13 certs for the LocalMachine\Personal store.   When I run my code against the same store I get 0 certificates enumerated.  Am I doing this wrong?

     private void cmdRetrieveCerts_Click(object sender, EventArgs e)
            {
                lstCertificates.Items.Clear();
                X509Store store = null;
    
                StoreName storeName = StoreName.My;
                StoreLocation storeLocation = StoreLocation.LocalMachine;
    
                store = new X509Store(storeName, storeLocation);
    
                foreach (var cert in store.Certificates)
                {
                    lstCertificates.Items.Add(cert.Subject);
                    cert.Reset();
                }
    
                store.Close();
            }

    VS2012

    .NET 4.5

    Windows 2012

    Thursday, November 7, 2013 5:07 PM

Answers

  • I am writing a winform app that will list all the certs from LocalMachine/My store in a list box.  When I run the MMC cert store snapin for my box (Windows 2012) I can see 13 certs for the LocalMachine\Personal store.   When I run my code against the same store I get 0 certificates enumerated.  Am I doing this wrong?

     private void cmdRetrieveCerts_Click(object sender, EventArgs e)
            {
                lstCertificates.Items.Clear();
                X509Store store = null;
    
                StoreName storeName = StoreName.My;
                StoreLocation storeLocation = StoreLocation.LocalMachine;
    
                store = new X509Store(storeName, storeLocation);
    
                foreach (var cert in store.Certificates)
                {
                    lstCertificates.Items.Add(cert.Subject);
                    cert.Reset();
                }
    
                store.Close();
            }

    VS2012

    .NET 4.5

    Windows 2012

    Doh!  Forgot to open the store.  You don't get error or anything back if store is not open.
    • Marked as answer by scott_m Thursday, November 7, 2013 5:09 PM
    Thursday, November 7, 2013 5:09 PM