Repository: tauri-apps/tauri (language: rust)

Issue:
[bug][installer] Installer launched from updater plugin may fails with `Failed to kill <APPNAME>. Please close it first then try again`
### Describe the bug

Installer launched from updater plugin may fails with `Failed to kill <APPNAME>. Please close it first then try again`, but it's actually exited already (by updater plugin)

This happens relatively rarely but have received reports from several users, and I may experience the problem/
It's hard to reproduce now, but when happens, retrying with updater would likely to cause same problem so some OS internal state is related I feel.


### Reproduction

Starting NSIS installer from updater plugin would cause problem, but not always.

### Expected behavior

No such error should happens

### Full `tauri info` output

```text
[✔] Environment
    - OS: Mac OS 15.0.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.83.0 (90b35a623 2024-11-26)
    ✔ cargo: 1.83.0 (5ffbef321 2024-10-29)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-aarch64-apple-darwin (default)
    - node: 22.6.0
    - pnpm: 8.15.4
    - npm: 10.8.2
    - deno: deno 1.45.5

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.2
    - tao 🦀: 0.30.8
    - tauri-cli 🦀: 2.0.0-rc.3
    - @tauri-apps/api : 2.1.1 (outdated, latest: 2.2.0)
    - @tauri-apps/cli : 2.1.0 (outdated, latest: 2.2.2)

[-] Plugins
    - tauri-plugin-dialog 🦀: 2.2.0
    - @tauri-apps/plugin-dialog : not installed!
    - tauri-plugin-single-instance 🦀: 2.2.0
    - @tauri-apps/plugin-single-instance : not installed!
    - tauri-plugin-updater 🦀: 2.3.0
    - @tauri-apps/plugin-updater : not installed!
    - tauri-plugin-fs 🦀: 2.2.0
    - @tauri-apps/plugin-fs : not installed!

[-] App
    - build-type: bundle
    - CSP: unset
    - frontendDist: out
    - devUrl: http://localhost:3030/
    - framework: React (Next.js)
    - bundler: Webpack
```


### Stack trace

_No response_

### Additional context

I feel something like TOCTOU problem in nsis-tauri-updater.

It looks `get_processes` (and underlying win32 api?) may returns pid for recently exited process, and `kill` doesn't check if `OpenProcess` fails with `0x80070057` (`E_INVALIDARG`).
As far as I tried with win 11, `OpenProcess` will fails with `E_INVALIDARG` if the process already exits.

https://github.com/tauri-apps/nsis-tauri-utils/blob/14d311b13f598508cfa48fae66db3cfb5a30d3bf/crates/nsis-process/src/lib.rs#L207-L231
https://github.com/tauri-apps/nsis-tauri-utils/blob/14d311b13f598508cfa48fae66db3cfb5a30d3bf/crates/nsis-process/src/lib.rs#L159-L164

For reference:
- if the process exited before `OpenProcess`, `OpenProcess` will fails with `0x80070057` (`E_INVALIDARG`)
- if the process exited between `OpenProcess` and `TerminateProcess`, `TerminateProcess` will fails with `0x80070005` (`E_ACCESSDENIED`)
- if the installer lacks privilege for killing the process, `OpenProcess` will fails with `0x80070005` (`E_ACCESSDENIED`). (I tested with killing cmd.exe running as SYSTEM)




Discussion / hints:

Fix patch:
diff --git a/.changes/bump-nsis-tauri-utils.md b/.changes/bump-nsis-tauri-utils.md
new file mode 100644
index 000000000000..3a7e11e81cd7
--- /dev/null
+++ b/.changes/bump-nsis-tauri-utils.md
@@ -0,0 +1,7 @@
+---
+tauri-bundler: 'patch:bug'
+---
+
+Bumped `nsis-tauri-utils` to `0.4.2` which fixes the following bugs:
+- Fixed launch on start checkbox in nsis installer does not work well with applications that require elevated permissions
+- Fixed nsis installer may fail to install if launched by updater plugin
diff --git a/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs b/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs
index 614aaad6e8c5..16d9df682954 100644
--- a/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs
+++ b/crates/tauri-bundler/src/bundle/windows/nsis/mod.rs
@@ -39,8 +39,8 @@ const NSIS_URL: &str =
 #[cfg(target_os = "windows")]
 const NSIS_SHA1: &str = "057e83c7d82462ec394af76c87d06733605543d4";
 const NSIS_TAURI_UTILS_URL: &str =
-  "https://github.com/tauri-apps/nsis-tauri-utils/releases/download/nsis_tauri_utils-v0.4.1/nsis_tauri_utils.dll";
-const NSIS_TAURI_UTILS_SHA1: &str = "F99A50209A345185A84D34D0E5F66D04C75FF52F";
+  "https://github.com/tauri-apps/nsis-tauri-utils/releases/download/nsis_tauri_utils-v0.4.2/nsis_tauri_utils.dll";
+const NSIS_TAURI_UTILS_SHA1: &str = "6532DA4545864C6EC95F62F27F2199BFD668560B";
 
 #[cfg(target_os = "windows")]
 const NSIS_REQUIRED_FILES: &[&str] = &[


Test patch: