Use w32.EnumerateProcesses instead of slower wmi in windows process.Processes()

This commit is contained in:
Lomanic 2017-11-12 20:24:44 +01:00
parent c9a24cf2d0
commit da12f10f63
1 changed files with 5 additions and 10 deletions

View File

@ -434,19 +434,14 @@ func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
// Get processes
func Processes() ([]*Process, error) {
var dst []Win32_Process
q := wmi.CreateQuery(&dst, "")
err := wmi.Query(q, &dst)
pids, err := Pids()
if err != nil {
return []*Process{}, err
}
if len(dst) == 0 {
return []*Process{}, fmt.Errorf("could not get Process")
return []*Process{}, fmt.Errorf("could not get Processes %s", err)
}
results := []*Process{}
for _, proc := range dst {
p, err := NewProcess(int32(proc.ProcessID))
for _, pid := range pids {
p, err := NewProcess(int32(pid))
if err != nil {
continue
}