Exemple #1
0
    static void Issue_386()
    {
        var project =
            new ManagedProject("ElevatedSetup",
                               new Dir(@"%ProgramFiles%\My Company\My Product",
                                       new File(@"Files\bin\MyApp.exe")));

        project.ManagedUI = ManagedUI.Default;
        project.AddAction(new ManagedAction(CustomActions.CheckIfAdmin,
                                            Return.check,
                                            When.Before,
                                            Step.AppSearch,
                                            Condition.NOT_Installed,
                                            Sequence.InstallUISequence));

        project.UIInitialized += (SetupEventArgs e) =>
        {
            if (!new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator))
            {
                MessageBox.Show(e.Session.GetMainWindow(), "You must start the msi file as admin", e.ProductName);
                e.Result = ActionResult.Failure;

                var startInfo = new ProcessStartInfo();
                startInfo.UseShellExecute  = true;
                startInfo.WorkingDirectory = Environment.CurrentDirectory;
                startInfo.FileName         = "msiexec.exe";
                startInfo.Arguments        = "/i \"" + e.MsiFile + "\"";
                startInfo.Verb             = "runas";

                Process.Start(startInfo);
            }
        };

        // project.PreserveTempFiles = true;
        Compiler.BuildMsi(project);
    }
 public InstallBuilder LaunchAfterInstallation()
 {
     _project.AddAction(new ManagedAction(CustomActions.LaunchProcess, Return.check, When.After, Step.InstallFinalize, Condition.NOT_Installed));
     return(this);
 }