Scriptomatic 2.0

Advance Technical Repair of Laptops Motherboard

Computer Repair Mastery Course

Get Instant Access

Network-drive query results

If you would like some additional help in the form of prewritten WMI queries, we have another tool for your consideration: a free download from Microsoft called Scriptomatic 2.0. (The URL is long and complicated so do a Google search on the keywords "Scriptomatic 2 download" to find a link to it.) Download the compressed executable file from Microsoft, extract the files, and double-click the ScriptomaticV2.hta file to execute. Figure 20.11 shows the Scriptomatic tool after initializing. After using it a few times you will find it to be one of the most invaluable tools at your disposal.

The Scriptomatic tool is a hypertext application (HTA), which means it is essentially a local web application. You can open the ScriptomaticV2.hta file in a text editor to see how it does its magic. Scriptomatic begins by loading all the namespaces available on the local computer. The default namespace is root\CIMv2 but you can choose any other namespace with the WMI Namespace drop-down. After selecting the appropriate namespace, use the WMI Class dropdown to select the class you want to query.

As you can see in Figure 20.11, we have selected the Win32_Logica1Disk class. The Scriptomatic tool created a VBScript that queries the class and displays all the class's attributes. To see the script in another programming language select that language from the Language frame on the right side.

To run the script, click the Run button near the top of the window. A list of output choices displays on the right side; by default the output is sent to a command prompt window. When you select the Plain Text output option a file named Output.txt is created, filled, and opened in Notepad. The HTML output option creates an Output.htm file and opens it in Internet Explorer, as shown in Figure 20.12. We'll leave it as an exercise for you to discover the results of the remaining output options.

You can save the script Scriptomatic created by clicking the Save button and supplying a path. You can also copy and paste the script into your script editor and modify it to suit your needs. Again, the best way to discover the Scriptomatic tool's true potential is to experiment with it. ScriptomaticV2.hta includes a read_me.doc file that describes more of the tool's functionality, along with a dose of humor from its creators, The Microsoft Scripting Guys.

Figure 2G.11

Scriptomatic 2.0 tool

Figure 2G.11

Scriptomatic 2.0 tool


Figure 20.12

Scriptomatic HTML output

I @ Scriptomatic HTML Output - Windows Internet Explorer

& & M Scriptomatic HTML 0... | | Qf T E T #

' [i^ Page ' *

¡Caption | C:


¡Compressed | False

|ConfigMan agerErrorCod e



|CreationClassName | Win32_LogicalDisk

¡Description | Local Fixed Disk

DevicelD C:

(□riveType | 3




FileSystem NTFS

|FreeSpace | G610374656


|MaximumComponentLength 1255

|MediaType | 12

|Name | C:


¡h Computer | Protected Mode: Off

I +; 100Z " j

The Scriptomatic tool produces code with a few common traits. The code uses an array of computer names, allowing you to run the same WMI query on multiple computers. It uses the same method of executing the WMI query. It also uses a For Each loop to cycle through each instance of the class in the query result set. You might question if this is necessary for all WMI classes—it really is.

The CIM itself defines many base classes that are inherited by other classes in the repository. These classes represent the hardware and software in a system. All WMI classes support multiple instances of any given class, which makes WMI flexible enough to represent any computer configuration imaginable.

Multiple class instances can also complicate the task of processing WMI data. Let's look at a simple computer system. We typically have a motherboard, at least one processor, and at least one hard drive (we didn't say it was a complete system). These would be represented by one instance of the Win32_MotherboardDevice class, one instance of the Win32_Processor class for each processor, and one instance of the Win32_DiskDrive class for each hard drive.

To get information about the processor we would execute a WMI query such as Select * from Win32_Processor. The query simply says "Get all properties of all the instances of the Win32_ Processor class." If you want the query to be more efficient you can specify only the properties you are interested in.

After executing the query you will process each instance of the Win32_Processor class that was returned. Depending on the computer system, this makes perfect sense. Servers tend to have multiple processors, while desktop clients tend to have a single processor. We cannot guarantee that every computer we contact has only one processor; therefore it makes sense to treat each query result set as if it contains more than one instance of the WMI class. The following example code shows how to execute a WMI query and process the result set:

WMIQuery = "Select * From Win32_Processor" Set ResultSet = WMILocator.ExecQuery(WMIQuery) For Each Result in ResultSet

WScript.Echo "Current Speed=" & Result.CurrentClockSpeed WScript.Echo "Max Speed=" & Result.MaxClockSpeed Next

However, most common computer systems have only one motherboard, correct? While it might not make sense to treat the query result set as if there is only one instance of the Win32_MotherboardDevice class, this is still how it should be treated. In fact, all query results should be treated as if they might have multiple instances of the WMI class. The WMI query is always going to return a collection of instances, even if there is only one instance in that collection.

That said, there is a shortcut you can take if you are absolutely sure there is only one instance of a class or if you want to process only the first instance in the collection. By executing an Exit For command after processing the properties of the first instance, you can bypass the rest of the loop. The following code example shows how to do this with the Win32_MotherboardDevice class:

WMIQuery = "Select * From Win32_MotherboardDevice" Set ResultSet = WMILocator.ExecQuery(WMIQuery) For Each Result in ResultSet

WScript.Echo "Caption=v & Result.Caption WScript.Echo "Description=" & Result.Description Exit For ' Displays only the first motherboard's data Next

Now that you have seen some of the basic WMI concepts, it is time to start using it. As with other useful pieces of code, we have created a WMIClass VBScript class for you.

Real World Scenario

Was this article helpful?

0 0
The Ultimate Computer Repair Guide

The Ultimate Computer Repair Guide

Read how to maintain and repair any desktop and laptop computer. This Ebook has articles with photos and videos that show detailed step by step pc repair and maintenance procedures. There are many links to online videos that explain how you can build, maintain, speed up, clean, and repair your computer yourself. Put the money that you were going to pay the PC Tech in your own pocket.

Get My Free Ebook

Post a comment