Sample code for 30+ languages & platforms
PowerBuilder

Find a Certificate in the "Other People" Windows Certificate Store

See more Certificates Examples

Demonstrates how to open the "Current User --> Other People" Windows certificate store, and locates a certificate matching an email address.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_CertStore
integer li_ReadOnly
oleobject loo_JsonE
oleobject loo_Cert

li_Success = 0

loo_CertStore = create oleobject
li_rc = loo_CertStore.ConnectToNewObject("Chilkat.CertStore")
if li_rc < 0 then
    destroy loo_CertStore
    MessageBox("Error","Connecting to COM object failed")
    return
end if

// The "AddressBook" is the "Other People" certificate store as shown in certmgr.msc
li_ReadOnly = 1
li_Success = loo_CertStore.OpenWindowsStore("CurrentUser","AddressBook",li_ReadOnly)
if li_Success <> 1 then
    Write-Debug loo_CertStore.LastErrorText
    destroy loo_CertStore
    return
end if

// Find the certificate for the email address:
loo_JsonE = create oleobject
li_rc = loo_JsonE.ConnectToNewObject("Chilkat.JsonObject")

loo_JsonE.UpdateString("email","joe@example.com")

loo_Cert = create oleobject
li_rc = loo_Cert.ConnectToNewObject("Chilkat.Cert")

li_Success = loo_CertStore.FindCert(loo_JsonE,loo_Cert)
if li_Success = 0 then
    Write-Debug loo_CertStore.LastErrorText
    destroy loo_CertStore
    destroy loo_JsonE
    destroy loo_Cert
    return
end if

Write-Debug "Found certificate: " + loo_Cert.SubjectDN


destroy loo_CertStore
destroy loo_JsonE
destroy loo_Cert