mirror of
https://github.com/Finesssee/ProxyPilot.git
synced 2026-11-19 02:17:46 +00:00
28 lines
588 B
Go
28 lines
588 B
Go
//go:build windows
|
|
|
|
package desktopctl
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/sys/windows"
|
|
)
|
|
|
|
func isProcessAlive(pid int) (bool, error) {
|
|
if pid <= 0 {
|
|
return false, nil
|
|
}
|
|
h, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid))
|
|
if err != nil {
|
|
// If we can't open it, assume it's not ours / not running.
|
|
return false, nil
|
|
}
|
|
defer windows.CloseHandle(h)
|
|
var code uint32
|
|
if err := windows.GetExitCodeProcess(h, &code); err != nil {
|
|
return false, fmt.Errorf("GetExitCodeProcess: %w", err)
|
|
}
|
|
// STILL_ACTIVE == 259
|
|
return code == 259, nil
|
|
}
|