Click here to Skip to main content
15,881,819 members
Articles / Programming Languages / VBScript

IIS Admin Base Object Wrapper for installing SSL Certificates

Rate me:
Please Sign up or sign in to vote.
4.44/5 (9 votes)
12 Feb 20046 min read 64.7K   1.5K   28  
A COM Interop wrapper for the IIS Admin Base Object that can be used to programmatically install SSL Certificates in IIS 5.0.
' CAPICOM constants. 
Const CAPICOM_MEMORY_STORE                        = 0
Const CAPICOM_LOCAL_MACHINE_STORE                 = 1
Const CAPICOM_CURRENT_USER_STORE                  = 2
Const CAPICOM_ACTIVE_DIRECTORY_USER_STORE         = 3
Const CAPICOM_SMART_CARD_USER_STORE               = 4

Const CAPICOM_STORE_OPEN_READ_ONLY                = 0
Const CAPICOM_STORE_OPEN_READ_WRITE               = 1
Const CAPICOM_STORE_OPEN_MAXIMUM_ALLOWED          = 2
Const CAPICOM_STORE_OPEN_EXISTING_ONLY            = 128
Const CAPICOM_STORE_OPEN_INCLUDE_ARCHIVED		  = 256

Const CAPICOM_CERTIFICATE_FIND_SHA1_HASH          = 0
Const CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME       = 1
Const CAPICOM_CERTIFICATE_FIND_ISSUER_NAME        = 2
Const CAPICOM_CERTIFICATE_FIND_ROOT_NAME          = 3
Const CAPICOM_CERTIFICATE_FIND_TEMPLATE_NAME      = 4
Const CAPICOM_CERTIFICATE_FIND_EXTENSION          = 5
Const CAPICOM_CERTIFICATE_FIND_EXTENDED_PROPERTY  = 6
Const CAPICOM_CERTIFICATE_FIND_APPLICATION_POLICY = 7
Const CAPICOM_CERTIFICATE_FIND_CERTIFICATE_POLICY = 8
Const CAPICOM_CERTIFICATE_FIND_TIME_VALID         = 9
Const CAPICOM_CERTIFICATE_FIND_TIME_NOT_YET_VALID = 10
Const CAPICOM_CERTIFICATE_FIND_TIME_EXPIRED       = 11
Const CAPICOM_CERTIFICATE_FIND_KEY_USAGE          = 12

Const SSLCertHashId = 5506
Const SSLStoreNameId = 5511
Const SSLStoreName = "MY"


' Get Computer Name
Dim wsNetwork
Set wsNetwork = CreateObject("WScript.Network")
Dim computerName
computerName = wsNetwork.ComputerName

' Open the store.
Dim store
Set store = CreateObject("CAPICOM.Store")
store.Open CAPICOM_LOCAL_MACHINE_STORE, SSLStoreName, CAPICOM_STORE_OPEN_READ_ONLY
' Find Certificate
Dim certificates
Set certificates = store.Certificates
Set certificates = certificates.Find(CAPICOM_CERTIFICATE_FIND_SUBJECT_NAME, computerName, False)
' Get Byte Array Thumbprint
Dim thumbprintByteArray
If certificates.Count < 1 Then
	WScript.Echo("Certificate not found!")
	Return
Else
	For Each certificate In certificates
		Dim hexThumbprint
		hexThumbprint = certificate.Thumbprint
		Dim certUtilities
		Set certUtilities = CreateObject("CAPICOM.Utilities")
		Dim binaryThumprint
		binaryThumbprint = certUtilities.HexToBinary(hexThumbprint)
		thumbprintByteArray = certUtilities.BinaryStringToByteArray(binaryThumbprint)
	Next
End If

' Open Metabase
Dim metaBase
Set metaBase = CreateObject("IIS.MSAdminBase")
' Set SSL Certificate
metaBase.SetMetabaseData SSLCertHashId, "/W3SVC/1", thumbprintByteArray
metaBase.SetMetabaseData SSLStoreNameId, "/W3SVC/1", SSLStoreName
WScript.Echo(stringData)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Systems Engineer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions