0

I'm getting unexpected results from the below JScript code. The Index property is returned even though I've only requested MACAddress.

What's going on here?

JScript:

var wmi, col, itr, obj;

wmi = GetObject('winmgmts:');
col = wmi.ExecQuery('SELECT MACAddress FROM Win32_NetworkAdapterConfiguration');
itr = new Enumerator(col);

for (; !itr.atEnd(); itr.moveNext()) {
  obj = itr.item();
  itr = new Enumerator(obj.Properties_)
  for (; !itr.atEnd(); itr.moveNext()) {
    obj = itr.item();
    WSH.echo(obj.name)
  }
}

Output:

Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.

Index
MACAddress
Helen
  • 87,344
  • 17
  • 243
  • 314
user710307
  • 13
  • 4

1 Answers1

1

This behavior is normal, the WMI always returns (if is present) the key property (a property that uniquely identifies an instance of a class) and the others specified in the WQL sentence.

RRUZ
  • 134,889
  • 20
  • 356
  • 483
  • Thank you for the answer. Are you aware of a *IsKeyProperty* method to determine if the item we've got is a key property? – user710307 May 09 '14 at 16:34
  • You must check the properties qualifiers for that http://msdn.microsoft.com/en-us/library/windows/hardware/ff566365%28v=vs.85%29.aspx – RRUZ May 09 '14 at 17:11