/// <inheritdoc /> public void LaunchUpdater(Version version, bool restart = true) { // Ensure that the current state is valid for this operation EnsureNotDisposed(); EnsureLockFileAcquired(); EnsureUpdaterNotLaunched(); EnsureUpdatePrepared(version); // Get package content directory path var packageContentDirPath = GetPackageContentDirPath(version); // Get original command line arguments and encode them to avoid issues with quotes var routedArgs = EnvironmentEx.GetCommandLineWithoutExecutable().GetString().ToBase64(); // Prepare arguments var updaterArgs = $"\"{_updatee.FilePath}\" \"{packageContentDirPath}\" \"{restart}\" \"{routedArgs}\""; // Decide if updater needs to be elevated var updateeDirPath = Path.GetDirectoryName(_updatee.FilePath); var isUpdaterElevated = !DirectoryEx.CheckWriteAccess(updateeDirPath); // Create updater process start info var updaterStartInfo = new ProcessStartInfo { FileName = _updaterFilePath, Arguments = updaterArgs, CreateNoWindow = true, UseShellExecute = false }; // If updater needs to be elevated - use shell execute with "runas" if (isUpdaterElevated) { updaterStartInfo.Verb = "runas"; updaterStartInfo.UseShellExecute = true; } // Create and start updater process var updaterProcess = new Process { StartInfo = updaterStartInfo }; using (updaterProcess) updaterProcess.Start(); }
/// <summary> /// Launches an external executable that will apply an update to given version, once this application exits. /// The updater can be instructed to also restart the application after it's updated. /// If the application is to be restarted, it will receive the same command line arguments as it did initially. /// </summary> public static void LaunchUpdater(this IUpdateManager manager, Version version, bool restart = true) => manager.LaunchUpdater(version, restart, EnvironmentEx.GetCommandLineWithoutExecutable());