سؤال

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?

هل كانت مفيدة؟

المحلول

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;
    
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top