Jump to content
Silver Black

UAC request minimized instead of full-screen

Recommended Posts

Hi, I have a routine that I've been using successfully for a long time  to start a process with admin rights elevation. But I've lately noticed that the UAC request is minimized in the task bar, instead I'd like it to appear full-screen as if the user had clicked on the executable himself. 

I'm using:

 

    FillChar(seExecShell, SizeOf(seExecShell), 0);
    seExecShell.cbSize := SizeOf(seExecShell);
    seExecShell.Wnd := hndCaller;
    seExecShell.fMask := SEE_MASK_NOCLOSEPROCESS;
    seExecShell.lpVerb := PWideChar(RUN_CMD);
    seExecShell.lpFile := PWideChar(fnFile);
    seExecShell.lpParameters := PWideChar(strParams);
    seExecShell.nShow := SW_SHOWNORMAL;
    Result := ShellExecuteEx(@seExecShell);
ShellExecuteEx(@seExecShell);

Then to manage the waiting for the the process to terminate:

GetExitCodeProcess(seExecShell.hProcess, ExitCode);

But even without waiting there is always the issue of the minimized UAC request.

Do you think there is a workaround or this is a "by-design" feature of Windows?

Edited by Silver Black
  • Like 1

Share this post


Link to post
Quote

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.

Source: Sertac Akyuz, StackOverflow.com

  • Like 1
  • Thanks 1

Share this post


Link to post
13 minutes ago, Silver Black said:

I don't want to disable it

My point was that your user can disable it which is why it may show up as you first described.

Secondly, if an option can be set it can be read, that way at least you would be able to alert the user that such a thing might occur..

 

Share this post


Link to post
On 10/21/2021 at 9:06 PM, David Heffernan said:

That's kind of odd. Does the same happen if you do this with a brand new vcl project? 

I've to try that with a brand new empty project, but it happens in two different project.

Share this post


Link to post
On 10/21/2021 at 6:13 PM, FredS said:

My point was that your user can disable it which is why it may show up as you first described.

Secondly, if an option can be set it can be read, that way at least you would be able to alert the user that such a thing might occur..

 

Ok, now I get it. But the problem is that I've not disabled it on my machine and the issue occurs. 

Share this post


Link to post

I see minimized / background UAC dialogs from time to time, and it is annoying as heck.

I can't really see a pattern, though - and I can't say 100% for sure, but I don't think our own app that requires elevation have behaved like this for me.

Mostly, it seems to be installers, or apps launched by installers?

Share this post


Link to post
On 10/25/2021 at 7:28 AM, Der schöne Günther said:

Is it just "your machine" or also others (virtual machines / Windows Sandbox)?

Also other VM/PC.

 

On 10/25/2021 at 8:34 AM, Lars Fosdal said:

I see minimized / background UAC dialogs from time to time, and it is annoying as heck.

I can't really see a pattern, though - and I can't say 100% for sure, but I don't think our own app that requires elevation have behaved like this for me.

Mostly, it seems to be installers, or apps launched by installers?

My app is an installer!

Share this post


Link to post

It is what happens when the application that called ShellExecute did not provide a HWND of a foreground window. What is the value of your 

hndCaller

? Maybe you passed something like Application.Handle? Compare to GetForegroundWindow - Is your value the same?

 

 

Share this post


Link to post
2 hours ago, Der schöne Günther said:

It is what happens when the application that called ShellExecute did not provide a HWND of a foreground window. What is the value of your

I also ran a couple of tests and it made no diff; Zero, GetDesktopHandle, GetActiveWindow, Application.Handle and Mainform.handle all appeared as normal.

 

 

 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×