JScript Enumerator and list of properties

前端 未结 3 1062
南方客
南方客 2021-02-06 11:45

Consider the following WSH snippet:

var query = GetObject(\"winmgmts:\").ExecQuery(\"SELECT Name FROM Win32_Printer\", \"WQL\", 0);
var e = new Enumerator(query);
for         


        
3条回答
  •  深忆病人
    2021-02-06 12:12

    I think the problem is in your query you're only asking for the Name. Try asking for both Name and status:

    var query = GetObject("winmgmts:").ExecQuery("SELECT Name, Status  FROM Win32_Printer", "WQL", 0);
    var e = new Enumerator(query);
    for ( ; !e.atEnd(); e.moveNext ()) { 
        var p = e.item();
        WScript.Echo(p.Name + " (" + p.Status + ")" );
    }
    

    I got some more properties from http://msdn.microsoft.com/en-us/library/aa394363(VS.85).aspx and several work. I queried for DriverName and Comment and both had text or at least a null.

    var query = GetObject("winmgmts:").ExecQuery("SELECT Name, Status, DriverName, Comment  FROM Win32_Printer", "WQL", 0);
    var e = new Enumerator(query);
    for ( ; !e.atEnd(); e.moveNext ()) { 
        var p = e.item();
        WScript.Echo(p.Name + " (" + p.Status + ") " + p.DriverName + " " + p.Comment);
    }
    

提交回复
热议问题