//go:build windows package main import "golang.org/x/sys/windows" const maxWindowsProcessImagePath = 32768 func processExecutablePath(pid int) (string, error) { handle, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pid)) if err != nil { return "", err } defer windows.CloseHandle(handle) buffer := make([]uint16, maxWindowsProcessImagePath) size := uint32(len(buffer)) if err := windows.QueryFullProcessImageName(handle, 0, &buffer[0], &size); err != nil { return "", err } return windows.UTF16ToString(buffer[:size]), nil }