user14733993
user14733993

Reputation:

How to enable UAC for a delphi program?

I enabled UAC from Project -> Options... -> Manifest enter image description here

but when the UAC prompted

enter image description here

and I select "No", the delphi .exe will not run at all. It will only run if I select "Yes".

I would like to ask if there is a way around this matter? Doesn't matter if I choose "Yes" or "No", the delphi .exe will still run as it suppose to with / without Administrator privilege.

Upvotes: 0

Views: 870

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 596307

Elevation happens only at process startup. A process cannot elevate itself dynamically once it has begun running.

To do what you are asking for ("Doesn't matter if I choose "Yes" or "No", the delphi .exe will still run as it suppose to with / without Administrator privilege"), you need to break up your program into 2 separate pieeces.

Have your main process run unelevated (Execution Level = "As Invoker") performing any tasks that don't require elevation.

Move your elevated tasks into either:

  • a separate EXE (Execution Level = "Highest Available" or "Require Administration") that you can run when needed.

  • a separate portion of your main EXE, ie invoked by command-line parameters, that you can run when needed using ShellExecute/Ex() with the "runas" verb.

  • a COM object that you can create and call into when needed using the COM Elevation Moniker.

Upvotes: 3

Related Questions