Launch Process Automation with WMI Trigger

by Aleksey Lazaryev, in Automation Strategy, posted 6/8/11
image for article

What is WMI?
WMI is Microsoft’s primary management enabling technology for Windows. If you manage Windows servers and workstations, or if you create Windows management applications, you will most likely be familiar with WMI. WMI is not just a three-letter acronym tossed around to impress your colleagues. Make no mistake, knowing how to use the WMI scripting library to create a vast array of Windows system administration scripts is utopia for WMI enthusiasts.

WMI Enthusiast

While you can use WMI to manage both local and remote computers, WMI provides a consistent approach to carrying out day-to-day management tasks. For example, you can:

  • Start a process on a remote computer.
  • Schedule a process to run at specific times on specific days.
  • Reboot a computer remotely.
  • Get a list of applications installed on a local or remote computer.
  • Query the Windows event logs on a local or remote computer.

These are just some examples, but there are a vast number of Windows processes and services that can be managed using WMI.

WMI Tools and Utilities
For those of us less adept in WMI, there are WMI tools and utilities that test (WBEMTest) and generate (Scriptomatic) WMI scripts. Let’s look at each utility:

Windows Management Instrumentation Tester
Most Windows operating systems have a utility called “Windows Management Instrumentation Tester” (or WBEMTest). WBEMTest is used to view and change Common Information Model (CIM) classes, instances, and methods. WBEMTest is also used to troubleshoot Windows Management Instrumentation (WMI) and programs that depend on WMI.

At the Run prompt, type wbemtest.exe and click OK. At the “Windows Management Instrumentation Tester” screen, select the “Connect” button to specify the following parameters:

Namespace: Default is root\cimv2

WMI Connect Dialog

The "Namespace" contains a hierarchy of classes and associations which define either a machine’s object or the relationship between two or more objects.

Once “Namespace” has been defined, select the “Query” button to put in your query.

WMI Query

On the “Query” screen, enter the WQL query statement that will execute. For example:

SELECT * FROM Win32_process WHERE name="notepad.exe"

Query Dialog

Click "Apply" to run the query and return the results.

is a free utility provided by Microsoft. It can be downloaded from Microsoft's website. This utility creates a script, in the selected language, that queries for ALL available attributes of the selected WMI class. Scriptomatic handles arrays, converts dates to a more readable format, and it works with all the WMI classes on your computer; on top of all that, it also writes scripts that can be run against multiple machines. One of the remarkable things about Sciptomatic is that it pre-populates WMI queries in any of four different languages: VBScript, Perl, JScript and Python.

Setting a WMI Trigger in AutoMate
The WMI trigger in AutoMate starts a task or workflow when a WQL query executes on a localhost or remote machine with an AutoMate BPA Server Agent installed. WMI uses the WMI Query Language (WQL) to submit WQL event queries and defines the type of events to be returned.  WQL is Microsoft’s proprietary query language, similar to how SQL is a standard query language for accessing databases.

Setting a WMI Trigger requires that you provide various WMI parameters such as the WQL Query statement, Namespace (which is pre-populated with root\CIMV2), and the machine location (i.e., local or remote) where the WMI trigger is set to execute. Fortunately for us all, WMI offers full support for WQL queries out of the box. As previously stated, the combination of Microsoft’s Scriptomatic and WBEMTest utilities provide the resources needed to successfully execute WMI scripts.

WMI Trigger Window

You can download a sample WMI Trigger task for a quick test drive here.