| 发表于:2007-03-28 19:43:32 楼主 |
我用这种方法得到相应进程的相关信息,其中用invokemethod()的方法得到进程用户名,但是效率相对太低(要多执行近1秒),希望高手提供一个效率高的方法得到这个项,最好用wql直接查询。 managementobjectcollection processbase = wmiquery( "* ", "win32_process "); foreach(managementobject obj in processbase) { console.write(obj.properties[ "processid "].value.tostring()); console.write(obj.properties[ "name "].value.tostring()); if (obj.properties[ "processid "].value.tostring() != "0 ") { object user = obj.invokemethod( "getowner ", null, new invokemethodoptions(null, timespan.maxvalue)); console.write(((managementbaseobject)user).properties[ "user "].value.tostring()); } else console.write( "system "); console.write(buffertable[obj.properties[ "processid "].value.tostring()].tostring()); console.writeline(obj.properties[ "workingsetsize "].value.tostring()); } 其中:protected managementobjectcollection wmiquery(string sltitems, string slttarget) { managementobjectsearcher msearcher = new managementobjectsearcher(); msearcher.scope = new managementscope(@ "\\localhost\root\cimv2 "); msearcher.query = new objectquery(string.format( "select {0} from {1} ", sltitems, slttarget)); return msearcher.get(); } |
|
|
|
|