次のスニペット:JScript.NET:列挙WMIコレクションJScript.NETで
%windir%\Microsoft.NET\Framework64\v4.0.30319\jsc.exe /platform:x64 wmi.js
と実行されますが、とWMI
呼び出しを変更:
col=wmi.ExecQuery("SELECT * From Win32_Process", "WQL", 32);
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);
}
がでコンパイル
コンパイルはまだ動作しますが、実行時には次のようになります。
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
の両方を列挙することができます。