Translating into JScript

If you account for the fact that JScript as a language looks rather different from VBScript, an attempt to translate the two examples into JScript for execution within the Windows Scripting Host yields code that is largely identical. JScript has excellent COM support and has a built-in GetObject() function that works in the same way as its VBScript counterpart. The most noticeable difference concerns collections: JScript does not have a language equivalent of the VBScript for...next loop, so WMI collections need to be wrapped in JScript Enumerator objects in order for their elements to be accessed. This is illustrated in the following JScript version of the earlier service-listing script:

 /* services.js - list services ...

Get Windows Management Instrumentation (WMI) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.