Skip to content

Commit 1a3dcdb

Browse files
Raphiikoamrbashir
andauthored
fix(core): fix nsis updater unable to launch installers requiring elevation, 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>
1 parent 8c0166f commit 1a3dcdb

2 files changed

Lines changed: 39 additions & 9 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'tauri': 'patch:bug'
3+
---
4+
5+
On Windows, fix NSIS installers requiring administrator rights failing to be launched by updater.

core/tauri/src/updater/core.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -709,15 +709,45 @@ fn copy_files_and_run<R: Read + Seek>(
709709

710710
let paths = read_dir(&tmp_dir)?;
711711

712+
let system_root = std::env::var("SYSTEMROOT");
713+
let powershell_path = system_root.as_ref().map_or_else(
714+
|_| "powershell.exe".to_string(),
715+
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
716+
);
717+
712718
for path in paths {
713719
let found_path = path?.path();
714720
// we support 2 type of files exe & msi for now
715721
// If it's an `exe` we expect an installer not a runtime.
716722
if found_path.extension() == Some(OsStr::new("exe")) {
723+
// we need to wrap the installer path in quotes for Start-Process
724+
let mut installer_arg = std::ffi::OsString::new();
725+
installer_arg.push("\"");
726+
installer_arg.push(&found_path);
727+
installer_arg.push("\"");
728+
717729
// Run the EXE
718-
Command::new(found_path)
719-
.args(config.tauri.updater.windows.install_mode.nsis_args())
720-
.args(&config.tauri.updater.windows.installer_args)
730+
Command::new(powershell_path)
731+
.args(["-NoProfile", "-WindowStyle", "Hidden"])
732+
.args(["Start-Process"])
733+
.arg(found_path)
734+
.arg("-ArgumentList")
735+
.arg(
736+
[
737+
config.tauri.updater.windows.install_mode.nsis_args(),
738+
config
739+
.tauri
740+
.updater
741+
.windows
742+
.installer_args
743+
.iter()
744+
.map(AsRef::as_ref)
745+
.collect::<Vec<_>>()
746+
.as_slice(),
747+
]
748+
.concat()
749+
.join(", "),
750+
)
721751
.spawn()
722752
.expect("installer failed to start");
723753

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

787817
// run the installer and relaunch the application
788-
let system_root = std::env::var("SYSTEMROOT");
789-
let powershell_path = system_root.as_ref().map_or_else(
790-
|_| "powershell.exe".to_string(),
791-
|p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
792-
);
793818
let powershell_install_res = Command::new(powershell_path)
794-
.args(["-NoProfile", "-windowstyle", "hidden"])
819+
.args(["-NoProfile", "-WindowStyle", "Hidden"])
795820
.args([
796821
"Start-Process",
797822
"-Wait",

0 commit comments

Comments
 (0)