Installing a certificate on VISTA

V

Vance

I have a need to install a certificate from an installation program.

I currently use a BAT file to install a certificate by issuing the following
lines

winhttpcertcfg.exe -i personal.pfx -c local_machine\My -a %computername%
certmgr.exe -add -c rootcert.cer -s -r localMachine root

This works on VISTA if I disable the UAC. However, it does not even prompt
for proper access if I have the UAC turned on. I have tried shelling the
command lines from an installation program, but it has the same problem.

How can I create a process with the proper credentials to install the
certificate? Are there APIs or .NET functions I could call to install the
certificate from my program without shelling to the Microsoft programs?

Can someone point me in the correct direction?

Vance
 
V

Vance

I can now import a certificate with a .CER extension programatically.
Thanks! However, When I do the same thing with a .PFX file, the certifacte
does not seem to register correctly. Obviously, I'm missing a key piece.
Can someone please point me in the proper direction for PFX files?

Here is my DOS command that works fine, but again, this doesn't work unless
the end user does a "run as" administrator, so I would prefer to do the
proper import programatically.

winhttpcertcfg -i Personal.pfx -c local_machine\My -a %computername%

My attempt at code to do the same thing is included below. The certificate
displays exactly the same in MMC, but it doesn't seem to work the same.
What am I doing wrong?


Private Sub btnPfx_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPfx.Click

Dim msg As String

Dim strComputername As String

strComputername = My.Computer.Name

Try

' Dim store As New X509Store("MY", StoreLocation.CurrentUser)

Dim store As New X509Store("MY", StoreLocation.LocalMachine)

store.Open((OpenFlags.ReadWrite))

Dim x509 As New X509Certificate2()

'Create X509Certificate2 object from .PFX file.

Dim rawData As Byte() = ReadFile(txtCertFilename.Text)

x509.Import(rawData)

'store the data

store.Add(x509)

store.Close()

MsgBox("Cert added")

Catch ex As Exception

msg = "Error: Information could not be written out for this certificate."

MsgBox(msg)

End Try

End Sub



Thanks again for your assistance!
 
V

Vance

My PFX file is not password protected, but I do appreciate the link to the
MSDN article. Perhaps I can find the answer in the article.

Thanks for your response!

Vance
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top