PowerBuilder
PowerBuilder
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 PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Cert
oleobject loo_CertStoreCU
integer li_ReadOnlyFlag
li_Success = 0
loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")
if li_rc < 0 then
destroy loo_Cert
MessageBox("Error","Connecting to COM object failed")
return
end if
li_Success = loo_Cert.LoadFromFile("qa_data/certs/example.cer")
if li_Success = 0 then
Write-Debug loo_Cert.LastErrorText
destroy loo_Cert
return
end if
loo_CertStoreCU = create oleobject
li_rc = loo_CertStoreCU.ConnectToNewObject("Chilkat.CertStore")
li_ReadOnlyFlag = 0
// "CurrentUser" and "My" are the exact keywords to select your user account's certificate store.
li_Success = loo_CertStoreCU.OpenWindowsStore("CurrentUser","My",li_ReadOnlyFlag)
if li_Success = 0 then
Write-Debug "Failed to open the CurrentUser/My certificate store for read/write."
destroy loo_Cert
destroy loo_CertStoreCU
return
end if
// Import the certificate into the CurrentUser/My certificate store.
li_Success = loo_CertStoreCU.AddCertificate(loo_Cert)
if li_Success = 0 then
Write-Debug loo_CertStoreCU.LastErrorText
destroy loo_Cert
destroy loo_CertStoreCU
return
end if
Write-Debug "Imported " + loo_Cert.SubjectCN
Write-Debug "Success."
destroy loo_Cert
destroy loo_CertStoreCU