Click here to Skip to main content
Click here to Skip to main content

Tagged as

Windows 7 workaround to drag & drop DLLs to GAC

, 15 Dec 2009
Rate this:
Please Sign up or sign in to vote.
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

Share

About the Author

Chuck Bevitt

United States United States
No Biography provided

Comments and Discussions

 
Questiondoesn't work man Pinmemberh_j_shakib20-Jun-13 7:41 
QuestionThank you! Pinmemberwbrussell19-Apr-13 7:19 
QuestionSorry , it does not work for my system. PinmemberMember 807340310-Jul-11 18:42 
GeneralMy vote of 5 PinmemberPrimeCipher1-Mar-11 11:11 
AnswerYou have to change a setting in the Local Security Policy PinmemberEric Murriguez18-Jun-10 13:23 
GeneralMy vote of 1 Pinmemberdata4use18-Dec-09 13:42 
GeneralMy vote of 1 PinmemberMichael Chourdakis16-Dec-09 12:21 
QuestionCan also turn User Account Control off PinmemberChuck Bevitt16-Dec-09 7:41 
GeneralSimple approach PinmemberConchur15-Dec-09 22:59 
GeneralRe: Simple approach PinmemberChuck Bevitt16-Dec-09 7:28 
GeneralRe: Simple approach PinmemberPrimeCipher1-Mar-11 11:09 
QuestionHow we do it Pinmemberjw12315-Dec-09 22:12 

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.

| Advertise | Privacy | Mobile
Web03 | 2.8.140827.1 | Last Updated 16 Dec 2009
Article Copyright 2009 by Chuck Bevitt
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid