Handling Errors

As you saw both in Chapter 3, “Examining the Filesystem with WMI,” and in the previous script, many WMI methods return a value that indicates whether they succeeded. Whenever a script takes an action that depends on that value, it is performing a kind of error handling. The previous script, for example, reboots a remote machine and uses the return value of the Reboot() method to spark conditional execution. If the reboot succeeds, it runs a line of code that outputs Computer rebooted. If the reboot fails, it handles the error by outputting Reboot failed. (This description does not hold if you attempt to run the script without relevant permissions, though.)

When working with WMI and VBScript, you will encounter only two types ...

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.