Using the CorrectShellExecuteHWND Fix

Applies To: Windows 7, Windows Vista

This section includes information about using the CorrectShellExecuteHWND compatibility fix, including the issue details, the intercepted APIs, and the recommended fix for a permanent solution.

CorrectShellExecuteHWND

CorrectShellExecuteHWND fixes an issue whereby an application passes a bad handle to a window (HWnd) value into an API call to ShellExecute*, which results in user account control (UAC) elevation. In this situation, the bad HWnd value causes Windows Vista to fail to prompt the end user for elevation and instead flashes the elevation request in the taskbar.

This compatibility fix inspects the HWnd value by using the IsWindow(HWND) API call. If the HWnd value appears to be invalid, the compatibility fix replaces the value with a currently active HWnd value, but only if the HWnd appears in the current process.

Investigating the Issue

Application-related issues that can be resolved by applying the CorrectShellExecuteHWND fix are typically detected when the taskbar starts to flash without changing the window focus. You can confirm that this issue is related to the CorrectShellExecuteHWND fix by performing these steps:

  1. Set a breakpoint on ShellExecute* and then check the HWnd argument.

  2. Search for the HWnd value by using the Spy++ utility that is distributed with Visual Studio.

Intercepted APIs

The following APIs are intercepted by the CorrectShellExecuteHWND compatibility fix.

  • ShellExecuteW

  • ShellExecuteA

  • ShellExecuteExW

  • ShellExecuteExA

Fixing Your Code

Applications should be modified so that the code calling ShellExecute* passes the currently active HWnd value.

See Also

Concepts

Windows Vista and Windows 7 Operating Systems