A long time ago when most of my development was on a Windows Server 2003 machine, we had a registry tweak that allowed us to quickly refresh dll's in the GAC by right-clicking the dll file and choosing a custom context menu item that would call a simple cmd script that would uninstall and reinstall the selected .dll. Eventually we upgraded to Windows Server 2008 R2 and UAC blocked this feature... How I missed it indeed...

Well after a little bit of tinkering I was able to get it working again and I thought I would share my results.

In concept, little is different from what we were doing before on Server 2003, we create a registry key under the dllfile Classes root in the registry that will 1) create the context menu item and 2) execute a supplied command, but the change is that the executed command now needs to run with elevated permisisons (gacutil needs elevated permissions).

After a little bit of searching, I came across this blog post from Michael Murgolo about his elevation powertoys for Windows (http://blogs.technet.com/b/elevationpowertoys/). This appeared to be what I was looking for!

After attempting to use his elevate utility with limited success (I'm sure I was not doing something correctly), I dug into the two scripts involved and found the one line in the vbscript that made my day:
objShell.ShellExecute strCommandLine, strArguments, "", "runas"

So without further ado, here is my solution.

This was written for Windows Server 2008R2 and .NET 4 and assumes that the gacutil.exe and related files are installed in "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\" – if any of these are different in your environment, you may need to tweak the instructions.

Create the following files; Save all of these files to C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\ and double-click the reg file to merge it into the registry. You should now be able to update dlls without having to stop and write a script or pull up a command prompt :)


This script will uninstall parameter %~n1 (the name of the first argument, sans drive, path, and extension) and then install parameter %~dpnx1 (the fully qualified name of the first parameter including drive, path, name, and extension).

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\GacRefresh.cmd
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /uf %~n1
"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\gacutil.exe" /if %~dpnx1


This script calls the GacRefresh.cmd script with elevated permissions (the "runas" parameter elevates) – This is the key to getting past the elevation requirement (gacutil requires elevated permissions). It expects and passes 1 parameter to GacRefresh.cmd.

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\GacRefresh.vbs
Set objShell = CreateObject("Shell.Application")
strArguments = WScript.Arguments(0)
objShell.ShellExecute "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\GacRefresh.cmd", strArguments, "", "runas"


This registry entry is what creates the context menu item and exposes it to the shell.

C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\GacRefresh.reg
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\dllfile\shell\Gacutil Refresh]
@="Gacutil Refresh (Administrator)"
[HKEY_CLASSES_ROOT\dllfile\shell\Gacutil Refresh\command]
@="wscript \"C:\\Program Files (x86)\\Microsoft SDKs\\Windows\\v7.0A\\Bin\\NETFX 4.0 Tools\\GacRefresh.vbs\" \"%1\""


I hope somebody finds this helpful and I am curious to see how others would accomplish this using alternate methods so I look forward to your comments!