Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for listcert.vbs

(view source code of listcert.vbs as plain text)

  1. ' List all certificates
  2. ' Version 0.10 ALFA
  3. ' Known issue:
  4. '     Not enough storage available for large amounts of data
  5. '     => display result immediately instead of appending to a string
  6. ' Written by Rob van der Woude
  7. ' http://www.robvanderwoude.com
  8.  
  9.  
  10. Option Explicit
  11.  
  12. Const CAPICOM_MEMORY_STORE                =   0
  13. Const CAPICOM_LOCAL_MACHINE_STORE         =   1
  14. Const CAPICOM_CURRENT_USER_STORE          =   2
  15. Const CAPICOM_ACTIVE_DIRECTORY_USER_STORE =   3
  16. Const CAPICOM_SMART_CARD_USER_STORE       =   4
  17.  
  18. Const CAPICOM_MY_STORE                    = "My"
  19. Const CAPICOM_CA_STORE                    = "CA"
  20. Const CAPICOM_ROOT_STORE                  = "Root"
  21.  
  22. Const CAPICOM_STORE_OPEN_READ_ONLY        =   0
  23. Const CAPICOM_STORE_OPEN_READ_WRITE       =   1
  24. Const CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED  =   2
  25. Const CAPICOM_STORE_OPEN_EXISTING_ONLY    = 128
  26. Const CAPICOM_STORE_OPEN_INCLUDE_ARCHIVED = 256
  27.  
  28. WScript.Echo "Personal Certificates : " & ListCerts( CAPICOM_CURRENT_USER_STORE, CAPICOM_MY_STORE )
  29.  
  30. WScript.Echo "CA Certificates       : " & ListCerts( CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_CA_STORE )
  31.  
  32. WScript.Echo "Root Certificates     : " & ListCerts( CAPICOM_LOCAL_MACHINE_STORE, CAPICOM_ROOT_STORE )
  33.  
  34.  
  35. Function ListCerts( myStoreLocation, myStoreName )
  36. 	Dim colCerts, objCert, objStore, strReturn
  37.  
  38. 	strReturn = ""
  39.  
  40. 	Set objStore = CreateObject( "CAPICOM.Store.2" )
  41.  
  42. 	objStore.Open myStoreLocation, myStoreName, CAPICOM_STORE_OPEN_READ_ONLY Or CAPICOM_STORE_OPEN_EXISTING_ONLY
  43.  
  44. 	Set colCerts = objStore.Certificates
  45.  
  46. 	strReturn = colCerts.Count & vbCrLf & vbCrLf
  47.  
  48. 	If colCerts.Count > 0 Then
  49. 		For Each objCert In colCerts
  50. 			strReturn = strReturn & "Issued By     : " & objCert.IssuerName    & vbCrLf
  51. 			strReturn = strReturn & "Subject Name  : " & objCert.SubjectName   & vbCrLf
  52. 			strReturn = strReturn & "Version       : " & objCert.Version       & vbCrLf
  53. 			strReturn = strReturn & "Is Valid      : " & objCert.IsValid       & vbCrLf
  54. 			strReturn = strReturn & "Valid From    : " & objCert.ValidFromDate & vbCrLf
  55. 			strReturn = strReturn & "Valid Until   : " & objCert.ValidToDate   & vbCrLf
  56. 			strReturn = strReturn & "Serial Number : " & objCert.SerialNumber  & vbCrLf
  57. 			strReturn = strReturn & "Thumbprint    : " & objCert.Thumbprint    & vbCrLf & vbCrLf
  58. 		Next
  59. 	End If
  60.  
  61. 	Set colCerts = Nothing
  62. 	Set objStore = Nothing
  63.  
  64. 	ListCerts = strReturn
  65. End Function
  66.  

page last modified: 2024-04-16; loaded in 0.0095 seconds