-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_windows.go
More file actions
40 lines (34 loc) · 1.03 KB
/
Copy pathprocess_windows.go
File metadata and controls
40 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//go:build windows
package main
import (
"os/exec"
"syscall"
)
const createNoWindow = 0x08000000
func configureCommand(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: createNoWindow}
}
func killProcessTree(pid int) {
if pid <= 0 {
return
}
cmd := exec.Command("taskkill", "/PID", intString(pid), "/T", "/F")
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: createNoWindow}
_ = cmd.Run()
}
func killSidecarOrphans() {
script := `
$pattern = 'codexpanel-node-sidecar|node-sidecar\.js|CodexPanel.*server\.js'
Get-CimInstance Win32_Process |
Where-Object {
$_.ProcessId -ne $PID -and
$_.CommandLine -and
($_.Name -eq 'node.exe' -or $_.Name -eq 'codexpanel-node-sidecar.exe') -and
$_.CommandLine -match $pattern
} |
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
`
cmd := exec.Command("powershell", "-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", script)
cmd.SysProcAttr = &syscall.SysProcAttr{CreationFlags: createNoWindow}
_ = cmd.Run()
}