managementpath p = new managementpath("\\\\servername\\root\\cimv2");
managementscope ms = new managementscope(p,oconn);
objectquery oq = new objectquery("select * from win32_process");
managementobjectsearcher query1 = new managementobjectsearcher(ms,oq);
managementobjectcollection querycollection1 = query1.get();
//列举所有对像,并显示在 listbox 中
foreach (managementobject service in querycollection1)
{
// 列表框中显示的是进程的名称和所在路径,当然还有其它信息,比如进程句柄、//进程优先级、现在的运行状态等,我们没有全部列举出来,感兴趣的话您可以自//己试试
listbox1.items.add("service: " + service["name"] + " filepath: " + service["executablepath"]);
}