Delphi external exe with admin privileges is minimized in Windows 8
Asked Answered
R

1

7

I have an issue where the Windows 8 User Account Control (UAC) popup is minimized when I execute a command line helper program that requests admin privileges in its manifest. The UAC popup window just blinks yellow in the Windows taskbar, causing a confusing user experience:

Minimized UAC

After clicking the taskbar icon, then the UAC alert shows:

UAC Alert

In Windows 7, the UAC alert is not minimized but shows in the foreground. Any thoughts on how to fix this in Windows 8?

For reference, my main application runs under user privilege and executes the helper program with ShellExecuteEx. I am setting ShellExecuteEx's TShellExecuteInfo.nShow to SW_SHOW.

Reeves answered 4/12, 2013 at 21:37 Comment(5)
The difference is your command line helper is not in the foreground for the former. Windows 7 behaves the same for non-foreground prompts.Provenance
Any way to foreground the command line helper?Reeves
Not sure. See "Use the HWND Property to Be Acknowledged as a Foreground Application" part here if it helps.Provenance
At a wild guess you're not passing in the correct window handle to ShellExecuteEx.Cytherea
@SertacAkyuz and @Petesh Thank you. I had a popup TForm that was executing the exe and I was specifying Application.Handle to ShellExecuteEx rather than the TForm.Handle (which has focus when executing the command line helper). +1s and I'll accept an answer if you like too.Reeves
P
9

MSDN says ".. you must pass a parent HWND with a ShellExecute .." and explains,

The UAC elevation mechanism uses the HWND as part of determining whether the elevation is a background or foreground elevation. If the application is determined to be a background application, the elevation is placed on the taskbar as a blinking button. ..

Be sure to supply your foreground window's handle to ShellExecuteEx.

Provenance answered 4/12, 2013 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.