Author: |
Carlos J. Quintero (Microsoft MVP) |
Applies to: |
Microsoft Visual Studio 2005 |
Date: |
April 2008 |
|
Microsoft Visual Studio 2008 |
Updated |
March 2013 |
|
Microsoft Visual Studio 2010 |
|
|
|
Microsoft Visual Studio 2012 |
Introduction
This article explains some considerations to take into account while designing
and creating a Visual Studio add-in to be run on Windows Vista, Windows 7 or
higher.
While on Windows XP by default every user is an administrator (although you can
create "standard" users) Windows Vista introduced a new feature named User
Account Control (UAC) which causes that by default even administrators run as
standard users. When they perform some action that requires admin rights (such
as modifying a file in the folder C:\Program Files or writing to the HKEY_LOCAL_MACHINE hive), the
operating system prompts for an "elevation prompt" if the application was designed so
(otherwise the application fails with the "Access denied" error or the calls are performed against a virtualized file system or registry if the administrator configured it so). Since most
developers are administrators and add-ins are intended for developers, it
could be that your add-in worked on Windows XP but it doesn't work on Windows
Vista.
You can learn more about the UAC feature in the following pages:
Understanding and Configuring User Account Control in Windows Vista
UAC: Standard
User Changes
More Information
To make your add-in work fine on Windows Vista, Windows 7 or higher with UAC
activated you should follow these design decisions:
1) The installer
- Decide whether you want to install the add-in for all users (requiring
administrator privileges) or only for the user installing it (not requiring
administrator privileges).
- If the installation is for all users (requiring administrator privileges):
- Set the installer to require admin rights.
- Install it in a subfolder of the C:\Program Files folder (C:\Program Files (x86) on Windows 64-bit). This is the folder for software used by all users)
- Register the add-in for all users placing the .AddIn file in one of the folders for all users that Visual Studio scans to search .AddIn
files. See the article INFO: Default .AddIn file locations for Visual Studio add-ins.
- Create the shortcuts in the Start menu, Programs for all users.
- Configure the add-in to load on startup (when Visual Studio is loaded)
in the XML .AddIn registration file (LoadBehavior tag with the value 1) because
since this file is in a restricted folder (for all users), if the developer is
not administrator he will not be able to change it
and chances are that he will want the add-in loaded on startup. This has two
implications:
- The add-in is loaded on startup for all the developers that
share the computer: in most cases the computer is not shared, but if not,
chances are that all developers will want or need the add-in loaded on startup.
- The developer, lacking admin rights, cannot change that setting. If some time
he needs to run Visual Studio without the add-in (to diagnose a problem or
similar), Visual Studio 2005 and 2008 (but not Visual Studio 2010) allow to hold the left Shift key while the
IDE is loaded to not load add-ins. Furthermore, Visual Studio 2008 and higher allows to use
the devenv.exe /SafeMode command-line switch to not load add-ins or packages (in Visual
Studio 2005 this command-line switch only disables packages, not add-ins).
- If the installation is for the user installing it (not requiring administrator
privileges):
- Set installer to not require admin rights.
- Install it in a folder of the user such as:
- Windows XP: "C:\Documents and Settings\<user>\Application Data"
- Windows Vista and higher: "C:\Users\<user>\AppData\Roaming"
Note: do not hardcode those locations since they can change for each operating system. Your setup can use CSIDL_APPDATA to retrieve it.
- Register the add-in for the user placing the .AddIn file in one of the
folders for the current user that Visual Studio scans to search .AddIn
files. See the article INFO: Default .AddIn file locations for Visual Studio add-ins.
- Create the shortcuts in the Start menu, Programs for the current user.
2) The add-in
- The add-in should not require admin rights at all, it should not issue
elevation prompts and it should not require virtualized file systems or registry
stores.
- Do not store settings that must be writable in the installation folder (C:\Program Files). Use a per-user folder such as:
- Windows XP: "C:\Documents and Settings\<user>\Application Data"
- Windows Vista and higher: "C:\Users\<user>\AppData\Roaming"
Note: do not hardcode those locations since they can change for each operating system. Your setup can use CSIDL_APPDATA to retrieve it.
You can provide initial settings in the installation folder and make your add-in
to copy them to the per-user folder when it is loaded if they don't exist there
already.
- Do not store settings that must be writable in the HKEY_LOCAL_MACHINE hive.
While your installer can write there settings common for all users, the
add-in should use the HKEY_CURRENT_USER hive instead to write per-user settings.
- As long as you follow the last two rules, you won't get "Access denied" errors
and you won't need elevation prompts or virtualized file systems or registry stores.
Related articles
Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)
|