Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(AutoIt) Backup Windows Current User / Personal Certificates to a .zipDemonstrates how to backup the certificates in the Windows registry-based Current User certificate store (in the "Personal" Logical Store as seen in certmgr.msc), to a zip archive. Certificates having an exportable private key are exported to .pfx files. Certificates with no private key, or with a non-exportable private key, are exported to .cer files. Obviously, this example only runs on Windows computers.
$oCertStore = ObjCreate("Chilkat.CertStore") Local $bReadOnly = True Local $bSuccess = $oCertStore.OpenCurrentUserStore($bReadOnly) If (Not $bSuccess) Then ConsoleWrite($oCertStore.LastErrorText & @CRLF) Exit EndIf Local $sPfxPassword = "secret" Local $bAllSuccess = True Local $iNumSuccess = 0 Local $oEntry $oZip = ObjCreate("Chilkat.Zip") $oZip.NewZip("qa_output/personalCerts.zip") $oCertData = ObjCreate("Chilkat.BinData") $oSbFilename = ObjCreate("Chilkat.StringBuilder") ; Iterate over the certificates in the Current User store. Local $iNumCerts = $oCertStore.NumCertificates Local $i = 0 While $i < $iNumCerts Local $oCert = $oCertStore.GetCertificate($i) ConsoleWrite("DN = " & $oCert.SubjectDN & @CRLF) $oSbFilename.SetString("cert") $oSbFilename.AppendInt($i + 1) Local $bHasPrivateKey = $oCert.HasPrivateKey() If (($bHasPrivateKey = True) And ($oCert.PrivateKeyExportable = True)) Then ; Export to a .pfx $bSuccess = $oCert.ExportToPfxBd($sPfxPassword,True,$oCertData) If ($bSuccess = True) Then $oSbFilename.Append(".pfx") $oEntry = $oZip.AppendBd($oSbFilename.GetAsString(),$oCertData) EndIf Else ; Export to a .cer $bSuccess = $oCert.ExportCertDerBd($oCertData) If ($bSuccess = True) Then $oSbFilename.Append(".cer") $oEntry = $oZip.AppendBd($oSbFilename.GetAsString(),$oCertData) EndIf EndIf If ($bSuccess <> True) Then $bAllSuccess = False Else $iNumSuccess = $iNumSuccess + 1 EndIf $i = $i + 1 Wend If ($iNumSuccess > 0) Then $bSuccess = $oZip.WriteZipAndClose() If ($bSuccess <> True) Then ConsoleWrite($oZip.LastErrorText & @CRLF) $bAllSuccess = False EndIf EndIf ConsoleWrite("All success = " & $bAllSuccess & @CRLF) |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.