Use w32.EnumerateProcesses instead of slower wmi in windows process.Processes()
This commit is contained in:
parent
c9a24cf2d0
commit
da12f10f63
|
@ -434,19 +434,14 @@ func (p *Process) getFromSnapProcess(pid int32) (int32, int32, string, error) {
|
||||||
|
|
||||||
// Get processes
|
// Get processes
|
||||||
func Processes() ([]*Process, error) {
|
func Processes() ([]*Process, error) {
|
||||||
var dst []Win32_Process
|
pids, err := Pids()
|
||||||
q := wmi.CreateQuery(&dst, "")
|
|
||||||
err := wmi.Query(q, &dst)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []*Process{}, err
|
return []*Process{}, fmt.Errorf("could not get Processes %s", err)
|
||||||
}
|
|
||||||
if len(dst) == 0 {
|
|
||||||
return []*Process{}, fmt.Errorf("could not get Process")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
results := []*Process{}
|
results := []*Process{}
|
||||||
for _, proc := range dst {
|
for _, pid := range pids {
|
||||||
p, err := NewProcess(int32(proc.ProcessID))
|
p, err := NewProcess(int32(pid))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue