Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with wmi
#1
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
#2
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
#3
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")
#4
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...
#5
Read in MSDN about the flags.
#6
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)
#7
Not the same. These 4 IDispatch methods are used by low-level code eg QM internal code, almost never in scripts.
#8
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....
#9
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.
#10
ok, far beyond my knowledge, but QM implementation.

Thread (really) closed.


Forum Jump:


Users browsing this thread: 1 Guest(s)