Tuesday 17 May 2011

Automate Personal Certificate Import

A VB Script to silently install a personal certficate for users. This can be used to automate certificate installation for users. You will need to get a copy of  winhttpcertcfg.exe utility to import the certificate.

 --------------------------------------------------
'Aim:       To silently install the given personal certificate
'--------------------------------------------------
Option Explicit

Dim objShell
Dim strCertTool, strCertPath, strCertPwd, strUserName, strAppCache, StrUserID, StrAppCacheServer
'--------------------------------------------------
'objShell = Windows Script Host Shell Object
'strCertTool = path to the tool used to do the import
'strCertPath = path to the certificate file
'strCertPwd = certificate password
'strUserName = current user in form DOMAIN\Username
'strAppCache = application cache location
'--------------------------------------------------

'-- build the required variables --'
Set objShell = CreateObject("WScript.Shell")
strAppCache = "\\msgchhost\" & StrUserID  &  "$\tsprofile\"
strUserName = objShell.ExpandEnvironmentStrings("%userdomain%") & "\" & objShell.ExpandEnvironmentStrings("%username%")
StrAppCacheServer = objShell.ExpandEnvironmentStrings("%app_cache%")
strCertTool = strAppCacheServer & "\Certificates\winhttpcertcfg.exe"
strCertPath = strAppCache & "certificatename.pfx"
strCertPwd = "xxxx"
msgbox strCertpath
'-- run the tool in a hidden window --'
objShell.Run strCertTool & " -i " & strCertPath & " -a " & strUserName & " -c CURRENT_USER\My -p " & strCertPwd, 0, True

'-- Clean Up --'
Set objShell = Nothing

WScript.Quit 0

No comments:

Post a Comment