26f897c1ec
release / release-please (push) Failing after 1m49s
docs / build (push) Failing after 6m34s
release / build-and-upload (arm64, linux) (push) Has been cancelled
release / build-and-upload (arm64, windows) (push) Has been cancelled
release / build-darwin (amd64, darwin) (push) Has been cancelled
release / checksums (push) Has been cancelled
release / finalize (push) Has been cancelled
release / build-darwin (arm64, darwin) (push) Has been cancelled
release / build-and-upload (amd64, linux) (push) Has been cancelled
release / build-and-upload (amd64, windows) (push) Has been cancelled
docs / deploy (push) Has been cancelled
39 lines
854 B
Go
39 lines
854 B
Go
//go:build windows
|
|
|
|
package update
|
|
|
|
import (
|
|
"fmt"
|
|
"syscall"
|
|
"unsafe"
|
|
)
|
|
|
|
const processQueryLimitedInformation = 0x1000
|
|
|
|
var queryFullProcessImageNameW = syscall.NewLazyDLL("kernel32.dll").NewProc("QueryFullProcessImageNameW")
|
|
|
|
func defaultWindowsExecutablePathForPID(pid int) (string, error) {
|
|
handle, err := syscall.OpenProcess(processQueryLimitedInformation, false, uint32(pid))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
defer syscall.CloseHandle(handle)
|
|
|
|
size := uint32(32768)
|
|
buf := make([]uint16, size)
|
|
r1, _, callErr := queryFullProcessImageNameW.Call(
|
|
uintptr(handle),
|
|
0,
|
|
uintptr(unsafe.Pointer(&buf[0])),
|
|
uintptr(unsafe.Pointer(&size)),
|
|
)
|
|
if r1 == 0 {
|
|
if callErr != syscall.Errno(0) {
|
|
return "", callErr
|
|
}
|
|
return "", fmt.Errorf("query process image path: unknown error")
|
|
}
|
|
|
|
return syscall.UTF16ToString(buf[:size]), nil
|
|
}
|