Connecting to a Remote Machine

Accessing WMI objects on a remote machine, executing queries, and retrieving collections can be accomplished in exactly the same way as they are done locally. First you get a reference to a SWbemServices object on the remote machine, and then you use that SWbemServices object to service all further WMI requests. Performing the first step merely involves a call to GetObject() with a slightly extended moniker string; performing all further steps is absolutely identical to performing them locally.

So far in this book, we have been finding SWbemServices objects by passing the word "winMgmts:" as a moniker string to GetObject(). As we have already noted, this string is actually a shorthand notation for “the SWbemServices ...

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.