Skip to content

Commit

Permalink
fix(core): fix nsis updater unable to launch installers requiring ele…
Browse files Browse the repository at this point in the history
…vation, closes #7184 (#7185)

* Launch NSIS updaters requiring elevation from non-elevated process

* Add changes file

* remove detached process, use powershell

* Update updater-admin-launch-fix.md

---------

Co-authored-by: Amr Bashir <amr.bashir2015@gmail.com>
  • Loading branch information
Raphiiko and amrbashir committed Jun 19, 2023
1 parent 8c0166f commit 1a3dcdb
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changes/updater-admin-launch-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri': 'patch:bug'
---

On Windows, fix NSIS installers requiring administrator rights failing to be launched by updater.
43 changes: 34 additions & 9 deletions core/tauri/src/updater/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,15 +709,45 @@ fn copy_files_and_run<R: Read + Seek>(

let paths = read_dir(&tmp_dir)?;

let system_root = std::env::var("SYSTEMROOT");
let powershell_path = system_root.as_ref().map_or_else(
|_| "powershell.exe".to_string(),
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
);

for path in paths {
let found_path = path?.path();
// we support 2 type of files exe & msi for now
// If it's an `exe` we expect an installer not a runtime.
if found_path.extension() == Some(OsStr::new("exe")) {
// we need to wrap the installer path in quotes for Start-Process
let mut installer_arg = std::ffi::OsString::new();
installer_arg.push("\"");
installer_arg.push(&found_path);
installer_arg.push("\"");

// Run the EXE
Command::new(found_path)
.args(config.tauri.updater.windows.install_mode.nsis_args())
.args(&config.tauri.updater.windows.installer_args)
Command::new(powershell_path)
.args(["-NoProfile", "-WindowStyle", "Hidden"])
.args(["Start-Process"])
.arg(found_path)
.arg("-ArgumentList")
.arg(
[
config.tauri.updater.windows.install_mode.nsis_args(),
config
.tauri
.updater
.windows
.installer_args
.iter()
.map(AsRef::as_ref)
.collect::<Vec<_>>()
.as_slice(),
]
.concat()
.join(", "),
)
.spawn()
.expect("installer failed to start");

Expand Down Expand Up @@ -785,13 +815,8 @@ fn copy_files_and_run<R: Read + Seek>(
msiexec_args.extend(config.tauri.updater.windows.installer_args.clone());

// run the installer and relaunch the application
let system_root = std::env::var("SYSTEMROOT");
let powershell_path = system_root.as_ref().map_or_else(
|_| "powershell.exe".to_string(),
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
);
let powershell_install_res = Command::new(powershell_path)
.args(["-NoProfile", "-windowstyle", "hidden"])
.args(["-NoProfile", "-WindowStyle", "Hidden"])
.args([
"Start-Process",
"-Wait",
Expand Down

0 comments on commit 1a3dcdb

Please sign in to comment.