private void beginInstallUpdateExe(ApplicationUpdate update, bool restartApplication = true)
        {
            if (!File.Exists(update.UpdateFileLocalPath))
            {
                throw new Exception("Target update installer does not exist at the expected location.");
            }

            var systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);

            string filename, args;

            if (restartApplication)
            {
                string executingProcess = Process.GetCurrentProcess().MainModule.FileName;

                filename = update.UpdateFileLocalPath;
                args     = $"\"{filename}\" /passive /waitforexit"; // The /waitforexit argument makes sure FilterServiceProvider.exe is stopped before displaying its UI.
            }
            else
            {
                filename = update.UpdateFileLocalPath;
                args     = $"\"{filename}\" /passive /waitforexit";
            }

            try
            {
                if (!ProcessCreation.CreateElevatedProcessInCurrentSession(filename, args))
                {
                    logger.Error($"Failed to create elevated process with {System.Runtime.InteropServices.Marshal.GetLastWin32Error()}");
                }
            } catch (Exception ex)
            {
                logger.Error(ex);
            }
        }
Exemplo n.º 2
0
        private void beginInstallUpdateExe(ApplicationUpdate update, bool restartApplication = true)
        {
            if (!File.Exists(update.UpdateFileLocalPath))
            {
                throw new Exception("Target update installer does not exist at the expected location.");
            }

            var    systemFolder = Environment.GetFolderPath(Environment.SpecialFolder.System);
            var    email = PlatformTypes.New <IAuthenticationStorage>().UserEmail;
            var    fingerPrint = FingerprintService.Default.Value;
            var    userId = email + ":" + fingerPrint;
            string filename, args;

            if (restartApplication)
            {
                string executingProcess = Process.GetCurrentProcess().MainModule.FileName;

                filename = update.UpdateFileLocalPath;
                args     = $"\"{filename}\" /upgrade /passive /waitforexit /userid={userId}"; // The /waitforexit argument makes sure FilterServiceProvider.exe is stopped before displaying its UI.
            }
            else
            {
                filename = update.UpdateFileLocalPath;
                args     = $"\"{filename}\" /upgrade /passive /waitforexit /userid={userId}";
            }

            try
            {
                logger.Info("Starting update process " + filename + " " + args);
                if (!ProcessCreation.CreateElevatedProcessInCurrentSession(filename, args))
                {
                    logger.Error($"Failed to create elevated process with {System.Runtime.InteropServices.Marshal.GetLastWin32Error()}");
                }
            } catch (Exception ex)
            {
                logger.Error(ex);
            }
        }