(image string)
| 78 | } |
| 79 | |
| 80 | func findProcessID(image string) (uint32, error) { |
| 81 | const processEntrySize = 568 |
| 82 | snap, err := windows.CreateToolhelp32Snapshot(windows.TH32CS_SNAPPROCESS, 0) |
| 83 | if err != nil { |
| 84 | return 0, err |
| 85 | } |
| 86 | defer windows.Close(snap) |
| 87 | p := windows.ProcessEntry32{Size: processEntrySize} |
| 88 | for { |
| 89 | err := windows.Process32Next(snap, &p) |
| 90 | if err != nil { |
| 91 | break |
| 92 | } |
| 93 | s := windows.UTF16ToString(p.ExeFile[:]) |
| 94 | if strings.EqualFold(s, filepath.Base(image)) { |
| 95 | return p.ProcessID, nil |
| 96 | } |
| 97 | } |
| 98 | return 0, fmt.Errorf("no process for %s image", image) |
| 99 | } |
no test coverage detected