Posts: 795
Threads: 136
Joined: Feb 2009
Hi Gintaras, hi all
According to MSDN,
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_TapeDrive")
Wscript.Echo colItems.Count
So when using this code:
IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE AND ConfigManagerErrorCode =22" @ wbemFlagReturnImmediately|wbemFlagForwardOnly))
why
_i=col.Count
does produce a exception????
_i should be 4 on my computer.
TY
Posts: 795
Threads: 136
Joined: Feb 2009
VARIANT v
v=col.Count
out v.vt
stops on second line
Message is :
Error (RT) in <open ":4: /420">EnableNetwork: 0x80020009, Exception occured.
0x4005, Non specified error.
PS: text error translated, maybe not the exact english formulation
Posts: 12,092
Threads: 142
Joined: Dec 2002
Remove flags from wmi.ExecQuery. The flags should make faster in some cases.
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter WHERE PhysicalAdapter = TRUE AND ConfigManagerErrorCode =22")
Posts: 795
Threads: 136
Joined: Feb 2009
removing the flags does the trick, the question is why, and how did you find the answer...intuition, knowledge or
just tried????
completely lost there...
Posts: 12,092
Threads: 142
Joined: Dec 2002
Read in MSDN about the flags.
Posts: 795
Threads: 136
Joined: Feb 2009
ok, found this:
wbemFlagForwardOnly
32 (0x20)
Causes a forward-only enumerator to be returned. Use this flag in combination with wbemFlagReturnImmediately to request semisynchronous access. For more information, see Calling a Method.
You can only iterate (as in a VBScript For Each statement) through a forward-only enumerator one time. The memory containing the instances is released by WMI so that the enumerator cannot be rewound. Therefore, the SWbemObjectSet.Count method cannot be used since it requires rewinding the enumerator.
Just to end this, how to use the IDispatch col variable through it's only method? is it not supposed do the same?
GetTypeInfoCount
int o=col.GetTypeInfoCount(&_i)
out _i (outs 1)
out o (outs 0)
Posts: 12,092
Threads: 142
Joined: Dec 2002
Not the same. These 4 IDispatch methods are used by low-level code eg QM internal code, almost never in scripts.
Posts: 795
Threads: 136
Joined: Feb 2009
exact, found IDispatch in MSDN, my questions are irrelevant, sorry for that.....
Just last one: how QM determines the wmi object type is IDispatch, internal implementation?
Don't see any relation to IDIspatch in MSDN examples....
Posts: 12,092
Threads: 142
Joined: Dec 2002
It is how COM works. QM queries IDispatch interface because it is a special interface that can be used to call COM object methods that are unknown at compile time (no type library). At run time, when QM script calls a COM method through IDispatch, internally QM calls GetIDsOfNames and Invoke.
In WMI VB examples in MSDN there are no variable types specified. It means all variables are of VARIANT type (default in VB). COM variables are VARIANT(IDispatch) and in QM script can be assigned to IDispatch variables.
Posts: 795
Threads: 136
Joined: Feb 2009
ok, far beyond my knowledge, but QM implementation.
Thread (really) closed.