Posts: 795
Threads: 136
Joined: Feb 2009
str code=
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objItem in colItems
Wscript.Echo objItem.MACAddress
For Each strAddress in objItem.IPAddress
Wscript.Echo strAddress
Next
Next
this does the trick, why QM can't???
Posts: 12,092
Threads: 142
Joined: Dec 2002
Here works.
Macro Macro471
out
def wbemFlagReturnImmediately 16
def wbemFlagForwardOnly 32
IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)
IDispatch x
foreach x col
,out "----"
,str name=x.MACAddress
,out name
,;VARIANT v=x.IPAddress; out F"0x{v.vt}"
,ARRAY(VARIANT) a=x.IPAddress
,int i
,for i 0 a.len
,,out a[i]
Posts: 795
Threads: 136
Joined: Feb 2009
at last, yes!!!!!!!
was about to give up............
did not think to test ARRAY(VARIANT).
Many thanks Gintaras !!!!
Posts: 12,092
Threads: 142
Joined: Dec 2002
Function OutVariantType
;/
function VARIANT&v
;Shows VARIANT variable type in QM output: VT_ constant, matching QM type, and for some types a note.
if(v.vt&0x9F00) out "unsupported flags in vt"; ret
lpstr csv=
;VT_EMPTY,,the VARIANT is not set
;VT_NULL,,means there is no data
;VT_I2,word,signed
;VT_I4,int
;VT_R4,FLOAT
;VT_R8,double
;VT_CY,CURRENCY
;VT_DATE,DATE
;VT_BSTR,str
;VT_DISPATCH,IDispatch
;VT_ERROR,int,used for omitted optional arguments
;VT_BOOL,word,"QM does not have a bool type. Physically it is 2-byte integer, like word. Value 0 is FALSE, 0xFFFF or other is TRUE."
;VT_VARIANT,VARIANT
;VT_UNKNOWN,IUnknown
;VT_DECIMAL,DECIMAL
;
;VT_I2,byte,signed
;VT_UI1,byte
;VT_UI2,word
;VT_UI4,int,unsigned
;VT_I8,long
;VT_UI8,long,unsigned
;VT_INT,int
;VT_UINT,int,unsigned
ICsv x._create
x.FromString(csv)
int i=v.vt&0xff
if(i>=x.RowCount or i=15) out "unknown type"; ret
str u=x.Cell(i 0)
str q=x.Cell(i 1)
str n=x.Cell(i 2)
if(v.vt&0x2000) q-"ARRAY("; q+")"; u+"|VT_ARRAY"
if(v.vt&0x4000) q+"*"; u+"|VT_BYREF"
str r=F"VARIANT type: {u}[]QM type: {q}"
if(n.len) r+F"[]note: {n}"
out r
Posts: 795
Threads: 136
Joined: Feb 2009
yes, was aware of that, is somewhere in the reference manual of QM
Still 2 points:
1. some values are out of reach, even with this "debug" routine (especially when VT_NULL)
2. some enumerated interfaces return error message (when can't retreive one parameter) and I must put err routine in code
to not catch them as v.vt mismatch.
Posts: 795
Threads: 136
Joined: Feb 2009
reviving this...
example using Win32_NetworkAdapterConfiguration
code used:
IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)
IDispatch x
foreach x col
out "----"
VARIANT v=x.ArpAlwaysSourceRoute
out F"0x{v.vt}"
OutVariantType(v)
how to deal when :
1. variable is boolean like boolean ArpAlwaysSourceRoute
0x1
VARIANT type: VT_NULL
QM type:
note: means there is no data
does not work either with int (QM does not seems to hoeld a boolean type)
2.
IDispatch wmi._getfile("winmgmts:")
IDispatch col = wmi.ExecQuery("SELECT * FROM Win32_NetworkAdapter" @ wbemFlagReturnImmediately|wbemFlagForwardOnly)
IDispatch x
foreach x col
out "----"
VARIANT v=x.NetworkAddresses
0x1
VARIANT type: VT_NULL
QM type:
note: means there is no data
so how retreive data declared as string but neither str variable or variant v=NULL
Posts: 12,092
Threads: 142
Joined: Dec 2002
Probably cannot retrieve. Try various flags with ExecQuery, or different query string, but I don't think it can help.
Example when the VARIANT is VT_BOOL:
int enabled=x.IPEnabled
out enabled ;;-1 true, 0 false
Posts: 795
Threads: 136
Joined: Feb 2009
ok, will not search further this way then ....
TY as usual
|