Skip to content

Commit cea9e6e

Browse files
authored
fix(installer): handle NSIS uninstall process blockers (agentscope-ai#7336)
1 parent b480761 commit cea9e6e

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

console/src-tauri/nsis/manage-install-processes.ps1

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -160,12 +160,11 @@ function Test-IsQwenPawInstall {
160160
function Get-ScopedProcesses {
161161
param(
162162
[string]$Root,
163-
[int]$ExcludedProcessId = 0
163+
[int[]]$ExcludedProcessIds = @()
164164
)
165165

166166
$result = foreach ($process in @(Get-CimInstance Win32_Process)) {
167-
if ($ExcludedProcessId -gt 0 -and
168-
$process.ProcessId -eq $ExcludedProcessId) {
167+
if ($ExcludedProcessIds -contains $process.ProcessId) {
169168
continue
170169
}
171170
$path = Get-NormalizedPath -Path "$($process.ExecutablePath)"
@@ -181,14 +180,27 @@ function Get-ScopedProcesses {
181180
return @($result)
182181
}
183182

183+
function Get-NsisProcessIds {
184+
param([int]$ProcessId)
185+
186+
if ($ProcessId -le 0) {
187+
return @()
188+
}
189+
$process = Get-CimInstance Win32_Process -Filter "ProcessId = $ProcessId"
190+
return @($ProcessId, $process.ParentProcessId) |
191+
Where-Object { $_ -gt 0 } |
192+
Sort-Object -Unique
193+
}
194+
184195
function Test-IsAutomaticProcess {
185196
param(
186197
[object]$Process,
187198
[string]$Root
188199
)
189200

190201
$relative = $Process.ExecutablePath.Substring($Root.Length).TrimStart("\")
191-
if ($relative -ieq "binaries\qwenpaw-backend\qwenpaw-backend.exe" -or
202+
if ($relative -ieq "qwenpaw-desktop.exe" -or
203+
$relative -ieq "binaries\qwenpaw-backend\qwenpaw-backend.exe" -or
192204
$relative -ieq "binaries\qwenpaw-backend\qwenpaw.exe") {
193205
return $true
194206
}
@@ -244,15 +256,16 @@ try {
244256
}
245257

246258
Enable-NativeHostGate -Root $root
247-
$scoped = Get-ScopedProcesses -Root $root -ExcludedProcessId $NsisProcessId
259+
$nsisProcessIds = Get-NsisProcessIds -ProcessId $NsisProcessId
260+
$scoped = Get-ScopedProcesses -Root $root -ExcludedProcessIds $nsisProcessIds
248261
$automatic = @(
249262
$scoped | Where-Object {
250263
Test-IsAutomaticProcess -Process $_ -Root $root
251264
}
252265
)
253266
Stop-ProcessRecords -Processes $automatic
254267

255-
$remaining = Get-ScopedProcesses -Root $root -ExcludedProcessId $NsisProcessId
268+
$remaining = Get-ScopedProcesses -Root $root -ExcludedProcessIds $nsisProcessIds
256269
if ($remaining.Count -gt 0) {
257270
Write-Output "Close these processes before continuing:"
258271
Write-ProcessList -Processes $remaining -Root $root

0 commit comments

Comments
 (0)