I have an InnoSetup installer that can usually run as non-admin, but in some cases it needs to run with elevated privileges if a condition is met. So I set PrivilegesRequired
to lowest
to ensure it doesn't show the UAC prompt when not required, and if the condition is met, I try to restart it as admin like this:
if not ShellExec('runas', ExpandConstant('{srcexe}'), GetCmdTail(), '', SW_HIDE, ewNoWait, errorCode) then begin
MsgBox(SysErrorMessage(errorCode), mbError, MB_OK);
end;
But it always fail with error 5 : access denied.
Apparently it's not because I can't use the runas
verb: running another executable with that verb works fine, and shows the UAC prompt. I also tried copying setup.exe to the temp directory and running it from there, but the copy fails.
How can I restart my setup as admin?