Click here to Skip to main content
15,884,298 members
Articles / Operating Systems / Windows 7

Windows 7 workaround to drag & drop DLLs to GAC

Rate me:
Please Sign up or sign in to vote.
3.07/5 (7 votes)
15 Dec 2009Public Domain3 min read 82.3K   8   12
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


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Questiondoesn't work man Pin
h_j_shakib20-Jun-13 7:41
h_j_shakib20-Jun-13 7:41 
QuestionThank you! Pin
wbrussell19-Apr-13 7:19
wbrussell19-Apr-13 7:19 
QuestionSorry , it does not work for my system. Pin
Member 807340310-Jul-11 18:42
Member 807340310-Jul-11 18:42 
GeneralMy vote of 5 Pin
PrimeCipher1-Mar-11 11:11
PrimeCipher1-Mar-11 11:11 
AnswerYou have to change a setting in the Local Security Policy Pin
Eric Murriguez18-Jun-10 13:23
Eric Murriguez18-Jun-10 13:23 
GeneralMy vote of 1 Pin
Ozan Müyesseroğlu18-Dec-09 13:42
Ozan Müyesseroğlu18-Dec-09 13:42 
GeneralMy vote of 1 Pin
Michael Chourdakis16-Dec-09 12:21
mvaMichael Chourdakis16-Dec-09 12:21 
QuestionCan also turn User Account Control off Pin
Chuck Bevitt16-Dec-09 7:41
Chuck Bevitt16-Dec-09 7:41 
GeneralSimple approach Pin
Conchur15-Dec-09 22:59
Conchur15-Dec-09 22:59 
GeneralRe: Simple approach Pin
Chuck Bevitt16-Dec-09 7:28
Chuck Bevitt16-Dec-09 7:28 
GeneralRe: Simple approach Pin
PrimeCipher1-Mar-11 11:09
PrimeCipher1-Mar-11 11:09 
QuestionHow we do it Pin
jw12315-Dec-09 22:12
jw12315-Dec-09 22:12 

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

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