Click here to Skip to main content
Licence Public Domain
First Posted 15 Dec 2009
Views 40,270
Bookmarked 6 times

Windows 7 workaround to drag & drop DLLs to GAC

By | 15 Dec 2009 | Article
Drag & drop libraries to install and delete DLLs on Windows 7.

Introduction

I develop in Visual Studio, and I'm switching from XP on my workstation to Window 7 x64. One thing that annoyed me was that I can’t simply drag .NET library DLLs to the assembly folder to install them in the GAC, or select and delete them from the assembly folder to remove them from the GAC, as I had done on Windows XP. When I try to, I get an ‘access denied’ error, even though my domain login is in the Administrators group, and even though I start Windows Explorer with ‘Run as administrator’.

Apparently, Microsoft really wants you to create installation applets to install or remove libraries in the GAC. An alternative is to log on as the actual machine administrator, in which case, drag and drop to the GAC will work.

I like being able to easily add or delete libraries to the GAC on a development workstation, however, so I came up with a work-around to let me do this.

Background

The method is to create .bat command files that use gacutil.exe to add or delete the library, to capture the name of the library when the library file is dragged to the command file, and have the command file run as administrator. Windows 7 doesn’t allow you to set a .bat command file to run as administrator, so a shortcut is created for each command file, and the shortcut is set to run as administrator.

Using the Code

This method requires gacutil.exe. If you've installed Visual Studio, it should be somewhere on your PC. After installing Visual Studio 2008 on Windows 7 x64, I found it at: C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin. I've also found it at C:\Windows\Microsoft.NET\Framework\v1.1.4322 on a machine with XP and Visual Studio 2005. I copy gacutil to the same folder where I put the command files, for convenience (I use c:\bin).

Here's the code for the AddToGAC.bat command file that installs the library:

c:\bin\gacutil.exe /i %1
pause

Here's the code for the DeleteFromGAC.bat command file that deletes the library:

c:\bin\gacutil.exe /u %~n1
pause

Note that the pause statement is optional. AddToGAC.bat uses the complete path\name of the library file that was dragged and dropped, found in the %1 variable (the path\name becomes the first command parameter). DeleteFromGAC uses %~n1 to parse the file name (without the file extension) from the path\name, which is what gacutil wants to delete a library.

I found info on parsing the path\name command parameter here: http://windowsitpro.com/article/articleid/71819/jsi-tip-0494---how-to-parse-a-batch-parameter.html.

The last step is to create a shortcut to each of the command files on the desktop. Open the properties of each shortcut, click 'Advanced', and select 'Run as administrator'.

When you drag and drop a .NET strong-named library to the Add To GAC shortcut, the User Account Control dialog box will appear (it may me minimized). Click 'Yes', and the library will be added to the GAC. Likewise, when you drag and drop a library to the Delete From GAC shortcut, the same thing will happen, and the library will be removed from the GAC. Unfortunately, you can't drag the library from the assembly folder to delete it, you have to drag it from somewhere else - Windows won't allow dragging and dropping from the GAC.

Points of Interest

I'm a newbie on Window 7, so there may be a better way to do this. One thing I'll look into is if a policy setting somewhere could grant my domain user login rights to do this directly, as though I had logged on as the machine's administrator.

Please feedback if anyone has a better way.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

About the Author

Chuck Bevitt



United States United States

Member



Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
QuestionSorry , it does not work for my system. PinmemberMember 807340318:42 10 Jul '11  
GeneralMy vote of 5 PinmemberPrimeCipher11:11 1 Mar '11  
AnswerYou have to change a setting in the Local Security Policy PinmemberEric Murriguez13:23 18 Jun '10  
GeneralMy vote of 1 Pinmemberdata4use13:42 18 Dec '09  
GeneralMy vote of 1 PinmemberMichael Chourdakis12:21 16 Dec '09  
QuestionCan also turn User Account Control off PinmemberChuck Bevitt7:41 16 Dec '09  
GeneralSimple approach PinmemberConchur22:59 15 Dec '09  
GeneralRe: Simple approach PinmemberChuck Bevitt7:28 16 Dec '09  
GeneralRe: Simple approach PinmemberPrimeCipher11:09 1 Mar '11  
QuestionHow we do it Pinmemberjw12322:12 15 Dec '09  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web02 | 2.5.120517.1 | Last Updated 16 Dec 2009
Article Copyright 2009 by Chuck Bevitt
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid