Saturday, September 19, 2009

Open Visual Studio Solutions as Administrator

Recently, I tried to build a setup program using a Visual Studio Setup
Project, on Windows Vista. Rebuilding the project failed with an
access denied error on a VS(sth).tmp file in
C:\Users\myuser\AppData\Local\Temp. Eventually I found that running
Visual Studio from the Start Menu (where I had already configured it
to run on privileged mode) and opening my solution from VS did the
trick.

Then i said I'd like to have a way of having my deployment project
work while still opening the solution by double-clicking the .sln file
from the shell. Luckily, it is possible to add a Run as administrator
option to virtually any file type. This is very clearly explained in
http://www.howtogeek.com/howto/windows-vista/add-run-as-administrator-to-any-file-type-in-windows-vista/
.

Just create a .reg file with the following contents:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln\Shell\runas\command]
@="\"C:\\Program Files\\Common Files\\Microsoft
Shared\\MSEnv\\VSLauncher.exe\" \"%1\""

And use it to add the necessary tweak to your registry.

Now, you can right click on the .sln file, select Run as administrator
and you will be able to do the same actions as if you had opened
Visual Studio as an administrator, but will save some clicks.

Note: I also tried configuring VSLauncher to open in administrator
mode from the compatibility tab, as described in one of the comments
in https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=263221
but it seems not to work for me.

No comments: