故障解决:Failure adding assembly to the cache: Access denied. You might not have administrative credentials to perform this task. Contact your system administrator for assistance.

最近在做SharePoint的开发,利用VS2008编译后直接部署,执行gacutil时发现有时会出现以下错误:

Failure adding assembly to the cache: Access denied. You might not have administrative credentials to perform this task. Contact your system administrator for assistance.

找到的解决方案为:

This error is down to the Vista User Access Control (UAC) and whilst turning it off will resolve the issue it may not always be advisable or indeed possible (depending on the security policy).

A better solution than simply turning UAC off is to run the process as a 'Real' administrator or in UAC terms to elevate the process.

 

When UAC is turned on and you log in as an administrator you get given two access tokens as apposed to just one. The first access token is the ‘normal’ access token which has administrator rights and privileges and the second access token is a copy of the first token but with all the administrator stuff stripped out. Thus the second access token is equivalent of an access token granted to a standard user account. It is the second access token that is used by default when executing a process.

 

In other words when UAC is turned on all processes are run as a standard user by default regardless of whether or not the user is actually and administrator.

 

To get around this you need to explicitly tell the process to use the first access token and run as an actual administrator.

 

If you are using a program such as visual studio which needs to access the global assembly cache (GAC) then navigate to the visual studio executable (devenv.exe) in windows explorer and right click on it and select ‘Properties’.

 

Click on the ‘Compatibility’ tab.

 

At the bottom of the tab there should be an option called ‘Run this program as an administrator’ make sure it is selected.

 

Click ‘OK’

 

If visual studio is already open, close it and re-open it. You should now be prompted by the UAC prompt asking to allow the program to be run as an administrator. Click ‘Allow’.

 

Visual studio (and all child processes) should now be able to access the GAC.

 

If you are try to access the GAC via a command prompt (cmd.exe) then the process is slightly different. To do this type ‘cmd.exe’ into the windows ‘Start Search’ and it should then appear in the programs list.

 

Instead of clicking on it as you would normally do, right click and select ‘Run as administrator’. This open the command prompt with full administrator privileges (and will require an ‘Allow’ on the UAC prompt). You should now be able to gacutil without any problems.

 

但是,我使用的系统为Windows 2003 Server,因此打开属性后,并没有上文中提到的选择。我觉得其分析的原因应该是正确的。昨天的解决方法(另外启动一个Command Prompt(注意不是VS2008中的Visual Studio 2008 Command Prompt),然后手动执行gacutil即可。)被证明是错误的,又试了一招,执行以下命令,将GAC访问权限赋予使用的用户。

          CACLS %WINDIR%\assembly /e /t /p [DOMAIN|MACHINENAME]\useraccount:F

posted @ 2008-10-14 18:13  Gu-dong  阅读(4044)  评论(1编辑  收藏  举报