次の方法で共有


UAC Common Error Dialog Box Extensibility

Your extension may require elevated permissions to complete some commands when it is running on Windows Vista. To inform the user when elevated permissions are required for the current operation and prompt for additional action, Visual Studio includes a UAC Common Error dialog box. Commands can be written to detect when elevated permissions are required and display a custom implementation of the UAC Common Error dialog box, or suppress the UAC Common Error dialog box.

How the UAC Common Error Dialog Box is Displayed

When a command tries to access resources that require elevated permissions on Windows Vista, the operating system will return an ElevationRequired HRESULT. If the command returns this HRESULT to the Visual Studio shell, then Visual Studio will display the UAC Common Error dialog box. The dialog box shows an error message and gives the user the option to restart Visual Studio under elevated permissions. If the user chooses this option, Visual Studio will restart under administrator permissions and prompt the user for administrator credentials. After the user supplies credentials, Visual Studio will restart, and will reopen the last opened solution and preserve any other command-line switches that Visual Studio was opened with. Any existing commands that report their return code back to the shell will automatically take advantage of the UAC Common Error dialog box.

Suppressing the UAC Common Error Dialog Box

You can set a command to call the SuppressRestart method before it finishes. This will cause Visual Studio to display the standard Visual Studio error message instead of the UAC Common Error dialog box, which contains the button that restarts Visual Studio. By doing this, you can enable commands that would not be successful even under elevated permissions to override the UAC Common Error dialog box and display a common, consistent user interface. Setting the SuppressRestart parameter to TRUE will suppress the UAC Common Error dialog box; setting SuppressRestart to FALSE will explicitly override any previous command that set it to TRUE and force the Common Error dialog box to display.

Note that the last package that calls SetErrorInfo will override the behavior of any previous package that has called SetErrorInfo.

Implementing a Custom UAC Error Dialog Box

Package developers who expose commands can make them "UAC aware" and then provide their own custom dialog box or other response to an ElevationRequired error code from the operating system.

See Also

Concepts

Best Practices for Security in the Visual Studio SDK

Running Extensions on Windows Vista