Logo
PRB: Uninstaller of add-in for current user fails if Visual Studio set to execute as administrator

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio 2005
Date: September 2011    
       
Introduction

This article explains a problem that can happen when uninstalling an add-in for the current user (not for all users) using Visual Studio 2005.

More Information

Visual Studio 2005 requires to be run with administrator rights (this limitation was removed in Visual Studio 2008). The process file of Visual Studio is devenv.exe. There are several ways to execute Visual Studio 2005 as administrator:

  1. Right-click the devenv.exe file or shortcut to it and in the context menu click the "Run as administrator" menu entry. This approach requires to do it so every time and therefore is not the most friendly way.
  2. Show the properties window of a shortcut to devenv.exe, and in the "Shortcut" tab click the "Advanced..." button and check the "Run as administrator" option. This approach only affects that shortcut, not other shortcuts and not clicking the devenv.exe file directly or executing devenv.exe through automation.
  3. Show the properties window of the devenv.exe file or shortcut to it, and in the "Compatibility" tab check the "Run this program as an administrator" option. This approach affects any way of executing the devenv.exe process, either directly, with any shortcut or through automation. Windows 7 64-bit stores this setting in the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers, name "C:\Program Files (x86)\Microsoft Visual Studio 8\Common7\IDE\devenv.exe, data "RUNASADMIN".

When a Visual Studio add-in is loaded for the first time, typically it creates its commands, which the add-in should not delete when unloaded because keyboard bindings would be lost. Rather, the uninstaller of the add-in should delete them when the add-in is uninstalled. See the article HOWTO: Removing commands and UI elements during Visual Studio .NET add-in uninstallation.

To delete the commands, the uninstaller must execute a custom action with either of these approaches:

  • Executing the command-line devenv.exe /ResetAddin <myaddin> /Command File.Exit
  • Creating an instance of EnvDTE.DTE through automation (ex: CreateObject("VisualStudio.DTE.10.0")), iterating its DTE.Commands, and removing the ones that belong to the add-in.

Consider this scenario:

  • Visual Studio 2005 is set to execute as administrator with the approach #3 (devenv.exe always requires admin rights, no matter how it is launched).
  • The user is uninstalling an add-in that is only for the current user (not for all users), and therefore both the installer and uninstaller don't require admin rights, they use the user account of the developer (non-admin).

With any approach to delete the commands, since the uninstaller needs to execute the devenv.exe process and this process is set to run as administrator, the custom action would fail.

A workaround to this problem is to make the uninstaller to remove the registry entry indicated before, perform the custom action and restore it.

Related articles


Go back to the 'Resources for Visual Studio .NET extensibility' section for more articles like this


Top