1. Home
  2. Computing & Technology
  3. Visual Basic

VBScript - The System Administrator's Language - Part 2

By , About.com Guide

5 of 7

The Script Template

The basic script that you can use to display information from WMI looks like this:

~~~~~~~~~~~~~~~~~~~~~~~~~
Set objWMIService = GetObject( _
  "winmgmts:\\" & strComputerName & "\root\cimv2")
Set colItems = objWMIService.ExecQuery( _
  "Select * from WMI_ProcessName")
For Each objItem in colItems
  Wscript.Echo "ItemName: " & objItem.ItemPropertyName
Next
~~~~~~~~~~~~~~~~~~~~~~~~~

There's a little more to it, of course, but not much. The items in bold are what you have to figure out and add to make the script actually do something.

In brief, this is what this script does:

  • It connects to a specific WMI service using a namespace. (In this case, "\root\cimv2".)
  • It executes a query to retrieve a collection of items from a WMI Process.
  • It displays properties from each retrieved WMI process.

Returning to the wbemtest utility, suppose we were interested in whether a computer had a particular software driver installed. You could get this information on just one machine easily using Control Panel. But if you wanted to find out for a thousand machines on three continents, it could be a problem. If all of those machines are on a network, you could use a simple script to find out. We're not going to go into how to address all the machines on the network, but we will show you how to write the script for one machine. (I've seen simple diagnostic scripts distributed to non-networked machines on floppies as well!)

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB 6
  5. Learn VBScript
  6. VBScript - The System Administrator's Language - Part 2

©2009 About.com, a part of The New York Times Company.

All rights reserved.