1

How can I force Inno Setup to show UAC prompt if elevated privileges are required to run specific installator during my setup? Skipping to install this installator is not critical. I found out that I can specify AfterInstall function to test if privilege elevation is required (IsAdminLoggedOn()), but how to show UAC prompt to run this installator as specific user?

Megamozg
  • 975
  • 9
  • 15
  • 1
    You'd have to re-run the setup and that requires to remember what user already selected during the wizard steps. Something very similar was asked in [`this question`](http://stackoverflow.com/q/20197554/960757). – TLama Dec 09 '13 at 08:22
  • My case is quite different. There is no need to restart entire setup. I just want to run specific .exe during installation with elevated privileges. Your proposition about `runas` in question you pointed above helped me. Thank you! – Megamozg Dec 10 '13 at 03:53

1 Answers1

0

Found the solution. So, if you need to run specific installator with elevated privileges during your setup you need:

  1. Specify your installator in Files section as follows:

    [Files]
    Source: "SomeSetup.exe"; DestDir: "{tmp}"; AfterInstall: SomeSetupAfterInstall()
    
  2. In Code section you shall define SomeSetupAfterInstall(). There you should run your installator with runas verb using ShellExec if it is not admin launched setup. It might be like this:

    procedure SomeSetupAfterInstall();
    var
        ErrorCode: Integer;
        TmpPath: String;
        RunMethod: String;
    begin
        TmpPath:=ExpandConstant('{tmp}');
        if not IsAdminLoggedOn() then
        begin
            RunMethod := 'runas';
        end else
        begin
            RunMethod := '';
        end;
        ShellExec (RunMethod, TmpPath + '\SomeSetup.exe', '', '', 
                   SW_SHOW,  ewWaitUntilTerminated, ErrorCode);
    end;
    
Megamozg
  • 975
  • 9
  • 15
  • I assume this means you're running your own setup with `PrivilegesRequired=lowest`. Because otherwise the above would not be necessary. (Don't forget that the user might cancel the elevation, or not be able to elevate, so your application will need to gracefully handle this component not being present.) – Miral Dec 10 '13 at 07:44
  • Yep. The point is to allow non-administrative users install an application, but without some specific features. – Megamozg Dec 10 '13 at 11:34