Operator
JScript for...in not compatible with WMI objects, because, moreover, they are more complex than native JScript objects. WMI objects expose their collection of properties using the special property Properties_ , so to list all the available properties of an object, you need to list this collection, for example, you list the results of a query to access individual WMI objects. Each property of an object is represented by a SWbemProperty object, which has a Name , Value and other properties that provide information about the corresponding object.
This example will help you understand:
var query = GetObject("winmgmts:").ExecQuery("SELECT Name, Status FROM Win32_Printer"); var colPrinters = new Enumerator(query); var oPrinter, colProps, p; // Enumerate WMI objects for ( ; !colPrinters.atEnd(); colPrinters.moveNext()) { oPrinter = colPrinters.item(); // Enumerate WMI object properties colProps = new Enumerator(oPrinter.Properties_); for ( ; !colProps.atEnd(); colProps.moveNext()) { p = colProps.item(); WScript.Echo(p.Name + ": " + p.Value); } } ") ExecQuery ( "SELECT Name, Status FROM Win32_Printer");. var query = GetObject("winmgmts:").ExecQuery("SELECT Name, Status FROM Win32_Printer"); var colPrinters = new Enumerator(query); var oPrinter, colProps, p; // Enumerate WMI objects for ( ; !colPrinters.atEnd(); colPrinters.moveNext()) { oPrinter = colPrinters.item(); // Enumerate WMI object properties colProps = new Enumerator(oPrinter.Properties_); for ( ; !colProps.atEnd(); colProps.moveNext()) { p = colProps.item(); WScript.Echo(p.Name + ": " + p.Value); } } colPrinters.moveNext ()) { var query = GetObject("winmgmts:").ExecQuery("SELECT Name, Status FROM Win32_Printer"); var colPrinters = new Enumerator(query); var oPrinter, colProps, p; // Enumerate WMI objects for ( ; !colPrinters.atEnd(); colPrinters.moveNext()) { oPrinter = colPrinters.item(); // Enumerate WMI object properties colProps = new Enumerator(oPrinter.Properties_); for ( ; !colProps.atEnd(); colProps.moveNext()) { p = colProps.item(); WScript.Echo(p.Name + ": " + p.Value); } } colProps.moveNext ()) { var query = GetObject("winmgmts:").ExecQuery("SELECT Name, Status FROM Win32_Printer"); var colPrinters = new Enumerator(query); var oPrinter, colProps, p; // Enumerate WMI objects for ( ; !colPrinters.atEnd(); colPrinters.moveNext()) { oPrinter = colPrinters.item(); // Enumerate WMI object properties colProps = new Enumerator(oPrinter.Properties_); for ( ; !colProps.atEnd(); colProps.moveNext()) { p = colProps.item(); WScript.Echo(p.Name + ": " + p.Value); } }
Note that this script also displays the value of the DeviceID property, because it is a key property of the Win32_Printer class, so it is also retrieved to uniquely identify instances of the class.
Helen
source share