Sample code for 30+ languages & platforms
Xbase++

Import a Certificate (.cer file) into a Windows Certificate Store

See more Certificates Examples

Demonstrates how to import a certificate (without private key) into a Windows certificate store.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oCert
LOCAL oCertStoreCU
LOCAL nReadOnlyFlag

nSuccess := 0

oCert := CreateObject("Chilkat.Cert")

nSuccess := oCert:LoadFromFile("qa_data/certs/example.cer")
IF (nSuccess == 0)
    ? oCert:LastErrorText
    oCert:destroy()
    RETURN
ENDIF

oCertStoreCU := CreateObject("Chilkat.CertStore")
nReadOnlyFlag := 0

//  "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
nSuccess := oCertStoreCU:OpenWindowsStore("CurrentUser", "My", nReadOnlyFlag)
IF (nSuccess == 0)
    ? "Failed to open the CurrentUser/My certificate store for read/write."
    oCert:destroy()
    oCertStoreCU:destroy()
    RETURN
ENDIF

//  Import the certificate into the CurrentUser/My certificate store.
nSuccess := oCertStoreCU:AddCertificate(oCert)
IF (nSuccess == 0)
    ? oCertStoreCU:LastErrorText
    oCert:destroy()
    oCertStoreCU:destroy()
    RETURN
ENDIF

? "Imported " + oCert:SubjectCN
? "Success."

oCert:destroy()
oCertStoreCU:destroy()