소스 검색

refactor(cli/core/bundler): use absolute path for msiexec and powershell (#4884)

Amr Bashir 3 년 전
부모
커밋
4e8b122df6

+ 12 - 3
core/tauri/src/updater/core.rs

@@ -802,13 +802,18 @@ fn copy_files_and_run<R: Read + Seek>(
       msi_path_arg.push("\"\"\"");
 
       // run the installer and relaunch the application
-      let powershell_install_res = Command::new("powershell.exe")
+      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([
           "Start-Process",
           "-Wait",
           "-FilePath",
-          "msiexec",
+          "$env:SYSTEMROOT\\System32\\msiexec.exe",
           "-ArgumentList",
         ])
         .arg("/i,")
@@ -820,7 +825,11 @@ fn copy_files_and_run<R: Read + Seek>(
       if powershell_install_res.is_err() {
         // fallback to running msiexec directly - relaunch won't be available
         // we use this here in case powershell fails in an older machine somehow
-        let _ = Command::new("msiexec.exe")
+        let msiexec_path = system_root.as_ref().map_or_else(
+          |_| "msiexec.exe".to_string(),
+          |p| format!("{p}\\System32\\msiexec.exe"),
+        );
+        let _ = Command::new(msiexec_path)
           .arg("/i")
           .arg(found_path)
           .args(msiexec_args)

+ 2 - 2
tooling/bundler/src/bundle/windows/templates/install-task.ps1

@@ -16,7 +16,7 @@ if ((Test-Admin) -eq $false) {
     else {
         $InstallDirectory = Get-Location
         $ArgList = ('-File "{0}" -ChangeDir "{1}" -Elevated' -f ($myinvocation.MyCommand.Definition, $InstallDirectory))
-        Start-Process powershell.exe -WindowStyle hidden -Verb RunAs -ArgumentList $ArgList
+        Start-Process "$env:SYSTEMROOT\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle hidden -Verb RunAs -ArgumentList $ArgList
     }
     exit
 }
@@ -25,4 +25,4 @@ if ($ChangeDir -ne "") {
     # Change directories to the install path
     Set-Location -Path $ChangeDir
 }
-SCHTASKS.EXE /CREATE /XML update.xml /TN "Update {{{product_name}}} - Skip UAC" /F
+SCHTASKS.EXE /CREATE /XML update.xml /TN "Update {{{product_name}}} - Skip UAC" /F

+ 2 - 2
tooling/bundler/src/bundle/windows/templates/uninstall-task.ps1

@@ -15,9 +15,9 @@ if ((Test-Admin) -eq $false) {
     }
     else {
         $ArgList = ('-File "{0}" -Elevated' -f $myinvocation.MyCommand.Definition)
-        Start-Process powershell.exe -WindowStyle hidden -Verb RunAs -ArgumentList $ArgList
+        Start-Process "$env:SYSTEMROOT\System32\WindowsPowerShell\v1.0\powershell.exe" -WindowStyle hidden -Verb RunAs -ArgumentList $ArgList
     }
     exit
 }
 
-SCHTASKS.EXE /DELETE /TN 'Update {{{product_name}}} - Skip UAC' /F
+SCHTASKS.EXE /DELETE /TN 'Update {{{product_name}}} - Skip UAC' /F

+ 2 - 2
tooling/bundler/src/bundle/windows/templates/update-task.xml

@@ -37,7 +37,7 @@
   <Actions Context="Author">
     <Exec>
       <Command>cmd.exe</Command>
-      <Arguments>/c "msiexec.exe /i %TEMP%\\{{{product_name}}}.msi {{{msiexec_args}}} /promptrestart"</Arguments>
+      <Arguments>/c "%SYSTEMROOT%\System32\msiexec.exe /i %TEMP%\\{{{product_name}}}.msi {{{msiexec_args}}} /promptrestart"</Arguments>
     </Exec>
   </Actions>
-</Task>
+</Task>

+ 11 - 5
tooling/cli/src/dev.rs

@@ -308,11 +308,17 @@ fn kill_before_dev_process() {
       .unwrap()
       .store(true, Ordering::Relaxed);
     #[cfg(windows)]
-      let _ = Command::new("powershell")
-        .arg("-NoProfile")
-        .arg("-Command")
-        .arg(format!("function Kill-Tree {{ Param([int]$ppid); Get-CimInstance Win32_Process | Where-Object {{ $_.ParentProcessId -eq $ppid }} | ForEach-Object {{ Kill-Tree $_.ProcessId }}; Stop-Process -Id $ppid -ErrorAction SilentlyContinue }}; Kill-Tree {}", child.id()))
-        .status();
+    {
+      let powershell_path = std::env::var("SYSTEMROOT").map_or_else(
+        |_| "powershell.exe".to_string(),
+        |p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
+      );
+      let _ = Command::new(powershell_path)
+      .arg("-NoProfile")
+      .arg("-Command")
+      .arg(format!("function Kill-Tree {{ Param([int]$ppid); Get-CimInstance Win32_Process | Where-Object {{ $_.ParentProcessId -eq $ppid }} | ForEach-Object {{ Kill-Tree $_.ProcessId }}; Stop-Process -Id $ppid -ErrorAction SilentlyContinue }}; Kill-Tree {}", child.id()))
+      .status();
+    }
     #[cfg(unix)]
     {
       use std::io::Write;

+ 7 - 3
tooling/cli/src/info.rs

@@ -286,8 +286,12 @@ fn get_version(command: &str, args: &[&str]) -> crate::Result<Option<String>> {
 
 #[cfg(windows)]
 fn webview2_version() -> crate::Result<Option<String>> {
+  let powershell_path = std::env::var("SYSTEMROOT").map_or_else(
+    |_| "powershell.exe".to_string(),
+    |p| format!("{p}\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"),
+  );
   // check 64bit machine-wide installation
-  let output = Command::new("powershell")
+  let output = Command::new(&powershell_path)
       .args(&["-NoProfile", "-Command"])
       .arg("Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\WOW6432Node\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
       .output()?;
@@ -297,7 +301,7 @@ fn webview2_version() -> crate::Result<Option<String>> {
     ));
   }
   // check 32bit machine-wide installation
-  let output = Command::new("powershell")
+  let output = Command::new(&powershell_path)
         .args(&["-NoProfile", "-Command"])
         .arg("Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
         .output()?;
@@ -307,7 +311,7 @@ fn webview2_version() -> crate::Result<Option<String>> {
     ));
   }
   // check user-wide installation
-  let output = Command::new("powershell")
+  let output = Command::new(&powershell_path)
       .args(&["-NoProfile", "-Command"])
       .arg("Get-ItemProperty -Path 'HKCU:\\SOFTWARE\\Microsoft\\EdgeUpdate\\Clients\\{F3017226-FE2A-4295-8BDF-00C3A9A7E4C5}' | ForEach-Object {$_.pv}")
       .output()?;