在JScript.NET下面的代碼片段:JScript.NET:枚舉WMI集合
wmi.js
------
var wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\\\.\\root\\cimv2"),
col =null, prc=null;
col=wmi.ExecQuery("SELECT * From Win32_Process", "WQL", 32);
//col=wmi.InstancesOf("Win32_Process");
var e = new Enumerator(col);
for (; !e.atEnd(); e.moveNext()){
prc = e.item();
print(prc.CommandLine);
}
與編譯:
%windir%\Microsoft.NET\Framework64\v4.0.30319\jsc.exe /platform:x64 wmi.js
和執行,但與改變WMI
電話:
col=wmi.ExecQuery("SELECT * From Win32_Process", "WQL", 32);
彙編仍然有效,而執行給出:
Unhandled Exception: System.InvalidCastException:
Unable to cast COM object of type 'System.__ComObject' to interface type 'System.Collections.IEnumerable'.
This operation failed because the QueryInterface call on the COM component for the interface with IID '{496B0ABE-CDEE-11D3-88E8-00902754C43A}' failed due to the following error:
'No such interface supported (Exception from HRESULT: 0x80004002
我不明白爲什麼,因爲兩個 InstancesOf 和 ExecQuery文件說:
If successful, the method returns an SWbemObjectSet
此外,WSH的JScript可以枚舉兩InstancesOf
收集和ExecQuery
。