Skip to content

Commit fad5813

Browse files
authored
Merge pull request #948 from web3dev1337/fix/nsis-kill-node-before-install
fix: kill orphaned node.exe before NSIS install to prevent file lock error
2 parents 6dbfe5d + 067351e commit fad5813

4 files changed

Lines changed: 43 additions & 0 deletions

File tree

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Fix: NSIS installer "Error opening file for writing" on node.exe
2+
3+
## Problem
4+
Windows NSIS installer fails with "Error opening file for writing: C:\Users\AB\AppData\Local\agent-workspace\resources\backend\node\node.exe" when reinstalling after uninstall.
5+
6+
## Root Cause
7+
The bundled node.exe (backend server) is still running as an orphaned process after app close/uninstall, holding a file lock. The installer can't overwrite a locked file.
8+
9+
## Solution
10+
Add NSIS preinstall hook that kills node.exe and Agent Workspace.exe before file extraction.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
- [x] Investigate root cause (orphaned node.exe holding file lock)
2+
- [x] Research Tauri v2 NSIS hook API
3+
- [x] Create src-tauri/windows/hooks.nsh with PREINSTALL + PREUNINSTALL hooks
4+
- [x] Add installerHooks config to tauri.conf.json
5+
- [ ] Commit and push
6+
- [ ] Create PR

src-tauri/tauri.conf.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
"macOS": {
4646
"bundleName": "Agent Workspace"
4747
},
48+
"windows": {
49+
"nsis": {
50+
"installerHooks": "./windows/hooks.nsh"
51+
}
52+
},
4853
"resources": [
4954
"resources/backend/*",
5055
"resources/backend/config/**/*",

src-tauri/windows/hooks.nsh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; Agent Workspace NSIS installer hooks
2+
; Kills ONLY the node.exe spawned by Agent Workspace (path-filtered),
3+
; not the user's other Node.js processes.
4+
5+
!macro NSIS_HOOK_PREINSTALL
6+
; Kill any running Agent Workspace instance (safe — it's our app)
7+
nsExec::ExecToLog 'taskkill /IM "Agent Workspace.exe" /F'
8+
9+
; Kill ONLY node.exe running from the agent-workspace install directory.
10+
; Uses PowerShell path filter so we never touch the user's other Node processes.
11+
; -ErrorAction SilentlyContinue: no error if nothing to kill.
12+
nsExec::ExecToLog "powershell -NoProfile -Command $\"Get-Process -Name node -ErrorAction SilentlyContinue | Where-Object { $$_.Path -like '*agent-workspace*' } | Stop-Process -Force -ErrorAction SilentlyContinue$\""
13+
14+
; Let Windows release file handles
15+
Sleep 1000
16+
!macroend
17+
18+
!macro NSIS_HOOK_PREUNINSTALL
19+
nsExec::ExecToLog 'taskkill /IM "Agent Workspace.exe" /F'
20+
nsExec::ExecToLog "powershell -NoProfile -Command $\"Get-Process -Name node -ErrorAction SilentlyContinue | Where-Object { $$_.Path -like '*agent-workspace*' } | Stop-Process -Force -ErrorAction SilentlyContinue$\""
21+
Sleep 1000
22+
!macroend

0 commit comments

Comments
 (0)