Xerratus
Happily stressed out, since 1974


 
Thursday, December 07, 2006
<< Visual Studio 2005 on Vista; Error "Unable to start debugging on the web server"
Vista taskbar clock frozen in time >>

Real quick; in order to run the debugger in Visual Studio 2005 on Windows Vista, you need to run the application as an administrator.  For the past few days, I've been doing this by right clicking the Visual Studio shortcut in my start menu and selecting "Run as Administrator".  What I really want is for Windows Vista to remember that I always want to run this program as an administrator.  So after a quick check I found that you can set it in the properties to do just that.

To be sure it works consistently, I changed the properties on the actual application found in: Program Files\Microsoft Visual Studio 8\Common7\IDE

Only problem I found that I haven't figured out yet (mostly for lack of trying) is that opening a solution file (.sln) directly does not work.  Actually, it doesn't do anything; no prompts or IDE.  But for now, it's one less click. 

Wednesday, July 02, 2008 4:20:11 PM (Pacific Standard Time, UTC-08:00)
Part One: Forcing UAC for .sln Files

The reason why launching VS2005 through files does not work is because there is a proxy program involved (VSLauncher.exe). This results in the launcher being executed with guest permission, followed by it attempting to execute Visual Studio, which you have marked as requiring administrator permission. This is blocked, resulting in complete silence.

Luckily, after a bit of digging, I found a way to make this work properly in both situations (executed through the VS icon or launched by opening an associated file).

The first step is to follow the instructions which you have posted, marking the exe as requiring administrator permission. This takes care of launching VS through the icon. The next step is to prompt for administrative permission when launching *.sln files.

This little trick involves a powertoy from Microsoft. Download the powertoy found here. Run Elevation2008_06.exe and extract the files to a temporary directory. Next, browse to that directory with Windows Explorer, right click on ElevateCommand.inf and choose "Install." This installs a command called "elevate", which launches the program in its parameter with administrator permission. This can be used to force Visual Studio to launch with administrator permission when launched through a file association.

To force all .sln files to launch with administrator permission, open up the registry editor (type "regedit" in the start menu; I'm not responsible for any damage you do to your computer, etc. etc.). Navigate to HKEY_CLASSES_ROOT\VisualStudio.Launcher.sln\Shell\Open\Command and double click on the (Default) key in the right-hand panel. A dialog box will pop up allowing you to change the value.

It should contain the following initially:

"C:\Program Files\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe" "%1"

Replace it with the following data:

"C:\Windows\System32\elevate.cmd" "C:\Program Files\Common Files\Microsoft Shared\MSEnv\VSLauncher.exe" "%1"

Save the value and exit the registry editor. Now, every time you launch a .sln file, Visual Studio will prompt you for administrative permission!

-------------------------------------------------------------------

Part Two: Forcing UAC for Other File Types

This can be done for any file type, as well. To find the key that you must replace, following these steps:

Using the registry editor, open HKEY_CLASSES_ROOT. Browse to the key with the name of the file extension that you want to elevate (in this example, I will use .c). When you find this key, look in the right-hand pane. Check the value in the (Default) parameter. For .c, this should be:

VisualStudio.c.8.0

Next, browse to the key in HKEY_CLASSES_ROOT with the same name as this value. In this case, browse to the VisualStudio.c.8.0 key. Expand this key, and see if it contains the following key:

HKEY_CLASSES_ROOT\***KEYNAME***\Shell\Open\Command

In the case of VisualStudio.c.8.0, this key (HKEY_CLASSES_ROOT\VisualStudio.c.8.0\Shell\Open\Command) DOES exist. If this key DOES NOT exist, then repeat the step above (check the value of the (Default) key, find the key with the same name, then check for .\Shell\Open\Command again). Repeat until you find it.

When you have found the key that you are looking for, simply add "C:\Windows\System32\elevate.cmd" (including the quotes) to the beginning of the value, as we did for .sln in Part One. You can follow this process for any file type. In summary, after following these steps, HKEY_CLASSES_ROOT\VisualStudio.c.8.0\Shell\Open\Command will have the following value:

"C:\Windows\System32\elevate.cmd" "C:\Program Files\Microsoft Visual Studio8\Common7\IDE\devenv.exe" /dde

It takes some hacking, but after all, you're a programmer, right? ;)
Thursday, July 03, 2008 6:39:37 AM (Pacific Standard Time, UTC-08:00)
Thanks Senthryl, this great stuff.

I can't wait to try it.
Name
E-mail
Home page

Comment (Some html is allowed: a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview