| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- # Stops adb.exe, node.exe, and Python runtimes. With -OnlyKillProcessesUnderPath, only processes whose Path is under that folder (safe from Electron exit).
- param(
- [int[]] $ExcludeProcessIds = @(),
- [string] $OnlyKillProcessesUnderPath = ''
- )
- $ErrorActionPreference = 'SilentlyContinue'
- # True when node.exe belongs to Cursor install (Local\Programs\cursor or ...\cursor\resources\...).
- function Test-IsCursorEditorNode {
- param([string]$ProcPath)
- if (-not $ProcPath) {
- return $false
- }
- $normalized = $ProcPath.Replace('/', '\')
- if ($normalized -match '(?i)\\Programs\\cursor\\') {
- return $true
- }
- if ($normalized -match '(?i)\\cursor\\resources\\') {
- return $true
- }
- return $false
- }
- function Test-ShouldStopProcess {
- param($Proc)
- if ($ExcludeProcessIds -contains $Proc.Id) {
- return $false
- }
- if ($OnlyKillProcessesUnderPath -eq '') {
- return $true
- }
- $procPath = $Proc.Path
- if (-not $procPath) {
- return $false
- }
- $root = [System.IO.Path]::GetFullPath($OnlyKillProcessesUnderPath)
- $full = [System.IO.Path]::GetFullPath($procPath)
- return $full.StartsWith($root, [StringComparison]::OrdinalIgnoreCase)
- }
- function Stop-DevSidecarProcesses {
- $baseNames = @('adb', 'node', 'python', 'pythonw', 'python3')
- foreach ($baseName in $baseNames) {
- Get-Process -Name $baseName -ErrorAction SilentlyContinue |
- Where-Object {
- if ($baseName -eq 'node' -and (Test-IsCursorEditorNode -ProcPath $_.Path)) {
- return $false
- }
- Test-ShouldStopProcess -Proc $_
- } |
- Stop-Process -Force
- }
- }
- Stop-DevSidecarProcesses
- Write-Host '[OK] adb / node / python cleanup finished.'
|