03
Cert Backup
Posted by jbjorkman on April 3, 2009 underDeprecated: preg_replace() [function.preg-replace]: The /e modifier is deprecated, use preg_replace_callback instead in /var/www/myfoto.se/jbits.se/blog/wp-includes/formatting.php on line 82
VBScript, Windows
Option Explicit
'************ You have to have capicom.dll downloaded and registered...
on error resume next
Const SavePath="C:\System\ISA-Backups\Certs\"
Const CAPICOM_CERTIFICATE_SAVE_AS_PFX = 0
Const CAPICOM_CURRENT_USER_STORE = 2
Const CAPICOM_EKU_CLIENT_AUTH = 2
Const CAPICOM_EKU_CODE_SIGNING = 3
Const CAPICOM_EKU_EMAIL_PROTECTION = 4
Const CAPICOM_EKU_SERVER_AUTH = 1
Const CAPICOM_EKU_OTHER = 0
Const CAPICOM_EXPORT_DEFAULT = 0
Const CAPICOM_CERTIFICATE_INCLUDE_CHAIN_EXCEPT_ROOT = 0
Const CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN = 1
Const CAPICOM_CERTIFICATE_INCLUDE_END_ENTITY_ONLY = 2
Const CAPICOM_LOCAL_MACHINE_STORE = 1
Const CAPICOM_MY_STORE = "My"
Const CAPICOM_STORE_OPEN_EXISTING_ONLY = 128
Const CAPICOM_STORE_OPEN_READ_ONLY = 0
Const CAPICOM_STORE_SAVE_AS_PFX = 2
Const CR_DISP_ISSUED = &H3
Const CR_OUT_CHAIN = &H100
Const CR_OUT_BASE64 = &H1
Const CERT_SYSTEM_STORE_LOCAL_MACHINE = &H20000
Const CR_IN_BASE64 = &H1
Const CR_IN_PKCS10 = &H100
Dim oCert, oStore
Dim strDate
Dim strCmp
Dim strCertName
Dim strfname
Dim strPasswd
Set oStore = CreateObject ("CAPICOM.Store")
if Err.Number <> 0 Then
wscript.echo "CAPICOM NOT detected"
Wscript.Quit(1)
End if
StrDate=Year(Now) & "-" & right("0" & Month(Now),2) & "-" & right("0" & Day(Now),2)
StrCmp=WScript.CreateObject("WScript.Network").ComputerName
oStore.Open CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_MY_STORE, CAPICOM_STORE_OPEN_READ_ONLY
strPasswd=Inputbox("Enter password to encrypt pfx with")
For Each oCert in oStore.Certificates
strCertName=left(oCert.SubjectName,instr(oCert.SubjectName,",")-1)
strCertName=replace(strCertName,"CN=","")
strCertName=replace(strCertName,"OU=","")
strCertName=replace(strCertName,"*","x")
strCertName=replace(strCertName," ","-")
strCertName=replace(strCertName,".","-")
strfname=strCmp & "-" & left(oCert.ValidtoDate,10) & "-" & strCertName
oCert.Save savePath & strfname & ".pfx", strPasswd, CAPICOM_CERTIFICATE_SAVE_AS_PFX, CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN
Next