importing website certificate (.pfx) via script

HAQattaq

Limp Gawd
Joined
Dec 25, 2005
Messages
282
Currently i am talking each user through how to manually import a .pfx file in IE in order to give them access to a secure website. I'm trying to find a solution to import a website certificate (.pfx file) to multiple users either via script or command line.
The file sits on an open share on a file server that each user has mapped a drive to.

I found this link http://technet.microsoft.com/en-us/library/cc757595.aspx about importing a cert using vb to multiple servers but I'm really lost on how to interpret it. I just want something (batch file) that a user can click once on and the cert is installed for them automatically on their desktop PC. Each user has local admin rights.

Any ideas or thoughts would be greatly appreciated. Thx.
 
You could try using CAPICOM and VBScript.

http://www.microsoft.com/downloads/...3A-A843-462F-ABB5-FF88EA5896F6&displaylang=en

I wrote a PowerShell script the other day to import a pfx cert into the LocalMachine/My store on some servers, but that won't work here unless your users have PoSH installed on all of the machines.

You could create a batch script that will register the CAPICOM DLL on the client machine, then run the vbs to import the pfx file. I *think* the VBS script would look like this:

Code:
[B]rem AddCert.vbs[/B]
rem Create CAPICOM Store Object and Cert object
[COLOR="royalblue"][B]set oCertStore = CreateObject ("CAPICOM.Store")
set oCert = CreateObject ("CAPICOM.Certificate") [/B][/COLOR]

rem Open the cert store. 
rem Param 1 is the Store to use (2 = current user)
rem Param 2 is the location to use in the store
rem Param 3 is the Read/Write mode. 0 = R, 1 = W, 2 = RW
[B][COLOR="RoyalBlue"]oCertStore.Open 2, "My", 2[/COLOR]  [/B] 

rem Load the cert
rem Param 1 is the path to the pfx
rem Param 2 is the pfx file password
rem Param 3 is the [URL="http://msdn.microsoft.com/en-us/library/aa375716(VS.85).aspx"]key storage flag[/URL]. 
rem Param 4 is the [URL="http://msdn.microsoft.com/en-us/library/aa375705(VS.85).aspx"]key location [/URL](0 = Current User)
[COLOR="royalblue"][B]oCert.Load "C:\Pathtocert\Cert.pfx", "Cert Password", 1, 0[/B][/COLOR]

rem Then, you just need to add the cert to the store
[COLOR="royalblue"][B]oCertStore.Add oCert[/B][/COLOR]

And the batch file would look like this:
Code:
regsvr32 /i <path>\CAPICOM.DLL
cscript.exe <path>\AddCert.vbs

And, for good measure, here's the PowerShell script:
Code:
param($pfxpath, $password)

$Store = new-object -com CAPICOM.Store
$cert = new-object -com CAPICOM.Certificate

$store.open(2, "My", 2)
$cert.load($pfxpath, $password, 1, 0)
$store.add($cert)


Soo, I think that should work :)
 
It works. :)

Although, I do get a RegSvr32 error when attempting to register the capicom.dll.
"DllInstall entry point was not found"
If i just click thru the message, the certificate appears where it should in IE.
It's probably something to do with the /i switch in the command line.
 
Oh yeah. I think I tried that without the /i switch and it did the same thing. If you use the /s switch, it won't display the error so you don't have to worry about users screaming about it.

Glad to hear it worked!
 
Back
Top