sn.exe fails with Access Denied error message
Asked Answered
N

6

15

I get an Access is Denied error message when I use the strong name tool to create a new key to sign a .NET assembly. This works just fine on a Windows XP machine but it does not work on my Vista machine.

PS C:\users\brian\Dev\Projects\BELib\BELib> sn -k keypair.snk

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.21022.8
Copyright (c) Microsoft Corporation.  All rights reserved.

Failed to generate a strong name key pair -- Access is denied.

What causes this problem and how can I fix it?


Are you running your PowerShell or Command Prompt as an Administrator? I found this to be the first place to look until you get used to User Access Control or by turning User Access Control off.

Yes I have tried running PS and the regular command prompt as administrator. The same error message comes up.

Numismatist answered 15/8, 2008 at 2:1 Comment(0)
G
31

Yes I have tried running PS and the regular command prompt as administrator. The same error message comes up.

Another possible solution could be that you need to give your user account access to the key container located at C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys

Guthrun answered 15/8, 2008 at 2:22 Comment(3)
Damn, wish I could give more than +1. I love you SO!Grunberg
On Windows 7 the path is C:\Users\All Users\Microsoft\Crypto\RSA\MachineKeys. You may have to enable showing of hidden and system files to see the All Users folder.Embargo
On Win 10 its also C:\Users\All Users\Microsoft\Crypto\RSA. Facepalm that this must be done on every new install, but is not documented by Microsoft.Myopic
G
3

Are you running your PowerShell or Command Prompt as an Administrator? I found this to be the first place to look until you get used to User Access Control or by turning User Access Control off.

Guthrun answered 15/8, 2008 at 2:6 Comment(1)
It's User Account Control!Asphyxiant
G
3

Why not fire up sysinternals Process Monitor too see what you can see, it's the first thing I always do when I get any kind of access denied message?

http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

Geranium answered 15/8, 2008 at 3:43 Comment(0)
M
3

Just to update this a bit: I ran into the same problem on Vista. My local user on the PC had no problem but then we switched to a domain and my domain user (albeit having local admin rights) got "Access Denied". I granted my domain user access rights to C:\Users\All Users\Microsoft\Crypto\RSA\MachineKeys and that fixed it.

Megalith answered 29/11, 2009 at 21:8 Comment(2)
On Windows 7 it's C:\ProgramData\Microsoft\Crypto\RSA\MachineKeysMenopause
%ALLUSERSPROFILE%\Microsoft\Crypto\RSA\MachineKeysByssinosis
S
2

Some people rebuild their machines to resolve this problem, but it can be solved by giving user access to the key container C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys Each container created using sn.exe -i is located in the MachineKeys directory (unless you specify elsewhere). The default key container that is used by sn.exe is also in that location.

In case you reset your key container to a new one, and forget where it is.. you can reset the key container for the strong name utility using sn.exe -c. So, if the account access fix doesn't work, you may be using an alternate key store so a reset may be in order.

Senior answered 15/8, 2008 at 2:1 Comment(0)
O
0

Updating this for Win 10+:

The new path is: C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys

Since System is the owner of the folder, you will need to change it to a user or group that has Administrator access. Once you've done this, you can proceed to alter the permission on Everyone to Read/Write.

Officialism answered 12/4, 2023 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.