Microsoft Windows Vista Community Forums - Vistaheads
Driver Scanner 2009 - Free Scan Now



Welcome to the Microsoft Windows Vista Community Forums - Vistaheads, YOUR Largest Resource for Windows Vista related information.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so , join our community today!

If you have any problems with the registration process or your account login, please contact us.

Installing a certificate on VISTA

microsoft.public.windows.vista.security



Click On Your Flag for Translation
Simplified Chinese French Spanish Italian Portugeuse Japanese German Dutch
Reply
  #1 (permalink)  
Old 03-06-2007
Vance
 

Posts: n/a
Installing a certificate on VISTA
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


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 03-06-2007
Haitao Li
 

Posts: n/a
Re: Installing a certificate on VISTA
You need way to elevate the commands or batch file. Have you tried
runas.exe?

You can call .NET functions to import a cert. See the sample code on this
page:
http://msdn2.microsoft.com/en-us/lib...tificate2.aspx

The process needs to be elevated if you import anything to machine root
store.

Haitao Li

"Vance" <vtemeyer@yahoo.com> wrote in message
news:uBy4#q$XHHA.4940@TK2MSFTNGP05.phx.gbl...
>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
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 03-09-2007
Vance
 

Posts: n/a
Re: Installing a certificate on VISTA
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!

"Haitao Li" <lht1999 [at] hotmail.com> wrote in message
news:35615EA4-CA4D-408D-B00E-1FE7D2CE739F@microsoft.com...
> You need way to elevate the commands or batch file. Have you tried
> runas.exe?
>
> You can call .NET functions to import a cert. See the sample code on this
> page:
> http://msdn2.microsoft.com/en-us/lib...tificate2.aspx
>
> The process needs to be elevated if you import anything to machine root
> store.
>
> Haitao Li
>
> "Vance" <vtemeyer@yahoo.com> wrote in message
> news:uBy4#q$XHHA.4940@TK2MSFTNGP05.phx.gbl...
>>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
>>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 03-09-2007
Haitao Li
 

Posts: n/a
Re: Installing a certificate on VISTA
Is your PFX password protected? I have never done it before, but here is the
code from msdn: http://msdn.microsoft.com/msdnmag/is...3/NETSecurity/

X509Certificate2 cert2 = new X509Certificate2("alice.pfx", password);


"Vance" <vtemeyer@yahoo.com> wrote in message
news:ut8FlqlYHHA.3272@TK2MSFTNGP03.phx.gbl...
>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!
>
> "Haitao Li" <lht1999 [at] hotmail.com> wrote in message
> news:35615EA4-CA4D-408D-B00E-1FE7D2CE739F@microsoft.com...
>> You need way to elevate the commands or batch file. Have you tried
>> runas.exe?
>>
>> You can call .NET functions to import a cert. See the sample code on this
>> page:
>> http://msdn2.microsoft.com/en-us/lib...tificate2.aspx
>>
>> The process needs to be elevated if you import anything to machine root
>> store.
>>
>> Haitao Li
>>
>> "Vance" <vtemeyer@yahoo.com> wrote in message
>> news:uBy4#q$XHHA.4940@TK2MSFTNGP05.phx.gbl...
>>>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
>>>

>
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 03-09-2007
Vance
 

Posts: n/a
Re: Installing a certificate on VISTA
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
"Haitao Li" <lht1999 [at] hotmail.com> wrote in message
news:E23697C7-CF18-43B8-8D66-45F957F3090F@microsoft.com...
> Is your PFX password protected? I have never done it before, but here is
> the code from msdn:
> http://msdn.microsoft.com/msdnmag/is...3/NETSecurity/
>
> X509Certificate2 cert2 = new X509Certificate2("alice.pfx", password);
>
>
> "Vance" <vtemeyer@yahoo.com> wrote in message
> news:ut8FlqlYHHA.3272@TK2MSFTNGP03.phx.gbl...
>>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!
>>
>> "Haitao Li" <lht1999 [at] hotmail.com> wrote in message
>> news:35615EA4-CA4D-408D-B00E-1FE7D2CE739F@microsoft.com...
>>> You need way to elevate the commands or batch file. Have you tried
>>> runas.exe?
>>>
>>> You can call .NET functions to import a cert. See the sample code on
>>> this page:
>>> http://msdn2.microsoft.com/en-us/lib...tificate2.aspx
>>>
>>> The process needs to be elevated if you import anything to machine root
>>> store.
>>>
>>> Haitao Li
>>>
>>> "Vance" <vtemeyer@yahoo.com> wrote in message
>>> news:uBy4#q$XHHA.4940@TK2MSFTNGP05.phx.gbl...
>>>>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
>>>>

>>
>>



Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding a certificate using MMC on a Vista Machine. =?Utf-8?B?U2NvdHQ=?= microsoft.public.windows.vista.security 11 02-22-2007 16:49
Vista asks to choose certificate when access shared folders =?Utf-8?B?SnU=?= microsoft.public.windows.vista.networking sharing 1 02-14-2007 13:24
Please help with installing MS certificate on Vista 32 bit. boe microsoft.public.windows.vista.installation setup 2 02-10-2007 00:53
SMTP over SSL - Certificate issue =?Utf-8?B?RFJN?= microsoft.public.windows.vista.mail 4 02-08-2007 06:15
Certificate problem Allan Riise microsoft.public.windows.vista.security 11 01-19-2007 19:34


All times are GMT +1. The time now is 14:50.


Driver Scanner 2009 - Free Scan Now

Driver Scanner 2 - Free Scan Now



Design by Vjacheslav Trushkin for phpBBStyles.com.
Powered by vBulletin® Version 3.6.7
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119