コード例 #1
0
        /// <summary>
        /// Configures the installer UI and logging operations before starting an operation.
        /// </summary>
        /// <param name="logFile">The path of the log file.</param>
        protected void ConfigureInstall(string logFile)
        {
            uint error = Error.SUCCESS;

            // Turn off the MSI UI.
            _ = WindowsInstaller.SetInternalUI(InstallUILevel.None);

            // The log file must be created before calling MsiEnableLog and we should avoid having active handles
            // against it.
            FileStream logFileStream = File.Create(logFile);

            logFileStream.Close();
            error = WindowsInstaller.EnableLog(InstallLogMode.DEFAULT | InstallLogMode.VERBOSE, logFile, InstallLogAttributes.NONE);

            // We can report issues with the log file creation, but shouldn't fail the workload operation.
            LogError(error, $"Failed to configure log file: {logFile}");
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: scott-the-programmer/sdk
        void InstallMsi(string path)
        {
            // Configure event handler for install messages
            UserInterfaceHandler ux = new UserInterfaceHandler(InstallLogMode.ACTIONDATA | InstallLogMode.ACTIONSTART | InstallLogMode.PROGRESS);

            ux.ActionData  += OnActionData;
            ux.ActionStart += OnActionStart;
            ux.Progress    += OnProgress;

            ProgressPhase = 0;

            Console.WriteLine();
            ActionTop      = Console.CursorTop;
            ProgressBarTop = ActionTop + 1;

            // Make sure we run quietly. Be careful, we won't be prompted to elevate.
            WindowsInstaller.SetInternalUI(InstallUILevel.None);

            uint error = WindowsInstaller.InstallProduct(path, "MSIFASTINSTALL=7 REBOOT=ReallySuppress");

            Console.CursorTop  = ProgressBarTop + 1;
            Console.CursorLeft = 0;

            Console.CursorTop = ActionTop;
            ClearLine();
            Console.CursorTop = ProgressBarTop;
            ClearLine();

            if ((error != Error.SUCCESS) && (error != Error.SUCCESS_REBOOT_INITIATED) && (error != Error.SUCCESS_REBOOT_REQUIRED))
            {
                throw new WindowsInstallerException((int)error);
            }
            else
            {
                Console.WriteLine("Done!");
            }
        }