【发布时间】:2017-01-25 22:51:32
【问题描述】:
在 JScript.NET 中如下 sn-p:
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 文档说:
如果成功,该方法返回一个 SWbemObjectSet
另外,WSH JScript 可以枚举InstancesOf 集合和ExecQuery。
【问题讨论】:
标签: collections wmi jscript wmi-query jscript.net