Windows IT Pro is the authoritative and independent resource for windows nt, windows 2000, windows 2003, windows xp. Features a collection of resources and magazines for windows IT professionals.
  
  
  Advanced Search 


October 22, 2004

Scrutinizing Scriptomatic

Does it really write scripts for you?
RSS
Subscribe to Windows IT Pro | See More VBScript Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

In my various Scripting Solutions articles, I walked you through the process of creating scripts as my grandfather would have: I made you walk uphill both ways in the snow while wearing shorts. (Perhaps it wasn't quite like that, but you get the idea.) As you've seen, this approach works well. However, once you start exploring the Windows Management Instrumentation (WMI) interface, you need a different approach. Before you write any code, you need to browse through the WMI software development kit (SDK) to find the objects you're looking for, then decipher which properties contain the information you need. Finding the correct class objects and properties can take a bit of practice and a lot of squinting at the screen. Fortunately, here's a tool on the Microsoft Web site that can help you with this drudgery: Scriptomatic.

In the documentation, Scriptomatic is billed as a utility that writes scripts for you. Well, it does and it doesn't. Scriptomatic does write working scripts—in fact, it's the basis for some of the scripts in the Microsoft TechNet Script Center. However, a novice scripter can't use Scriptomatic to create the types of scripts I've written for previous Scripting Solutions articles. (For links to those articles, go to http://www.windowsitpro.com/departments/departmentid/8/8.html.) Scriptomatic's basic function is to spit out property values for certain WMI classes on the local computer. To run the script on additional computers, pick up information from other sources, or evaluate or modify the data in any way, you need to edit the script manually. For this reason, I see Scriptomatic less of an automated scripting tool and more of a learning tool that lets you find the WMI classes and properties you need. After you have that information, it's a lot easier to open Notepad and create a more robust script that has some flexibility built into it. Using Scriptomatic takes away some of the donkey work of finding WMI classes and properties.

Scriptomatic is most useful when you have a little background in WMI. If you don't have that background, check out the Learning Path box. If you're familiar with WMI, read on and learn how to obtain and use Scriptomatic and how to edit its scripts.

Getting Started with Scriptomatic
The first step is to download the self-extracting file from the Microsoft Download Center. Go to http://www.microsoft.com/ downloads, search for scriptomatic, then click the Writing WMI Scripts Using the Scriptomatic Utility link. Download scriptomatic.exe. When you run scriptomatic.exe, the WinZip Self-Extractor decompress two files—scriptomatic .hta and a documentation file—in the C:\WindowsScriptsScriptomatic directory.

By default, Scriptomatic doesn't include any mechanism for connecting to remote computers, so you'll need to develop your scripts from a computer that will have all the WMI classes you need. This limitation won't necessarily hurt you—just make sure that you run Scriptomatic on a computer that has the same OS and WMI version as the computer on which you plan to run your WMI script.

If you must run Scriptomatic on a remote computer, here's a workaround you can use: Open scriptomatic.hta in Notepad. In the code, find the two instances of strComputer = ".". In each instance, replace the period (.) with the name of the target remote computer (e.g., strComputer = "atl-ws-01"). Save the file and, voila, you can retrieve WMI classes from that remote computer. Alternatively, the WMI CIM Studio in the WMI SDK lets you connect to any computer on your network that's running the WMI service.

Using Scriptomatic is straightforward. When you launch the tool, it automatically inventories the WMI classes available on the local computer, then displays the dialog box that Figure 1 shows. When you click the drop-down list in Figure 1, you get a list of Win32 classes available on that computer. (Only classes found in the root\cimv2 namespace are included because those classes are the most relevant for Windows scripting.) When you select a class, Scriptomatic automatically creates a script that, when run, displays all the class's properties on screen. For example, if you select the Win32_OperatingSystem class, you'll get a script similar to the one that Figure 2 shows. From this script, you can learn the proper names and format of the class's properties.

All the scripts created by Scriptomatic use basic VBScript statements and the Windows Script Host's (WSH's) Echo method to send, or echo, output to the screen. You can run a script from Scriptomatic or as a standalone .vbs file. To run a script from Scriptomatic, you simply click the Run button. If you plan to run the script as standalone file, you need to save it as a .vbs file. Before you run the script, I strongly recommend that you open a command-shell window and run the command

wscript //h:cscript //s

to make the command line (i.e., cscript.exe) rather than Windows (i.e., wscript.exe) the default script host. Otherwise, each echoed line of output requires you to click OK to progress to the next line. If you use Scriptomatic on a class such as Win32_NetworkAdapter, your hand will be immobilized with repetitive motion syndrome in no time flat. (If you use the Run button to launch a script, Scriptomatic automatically runs it under cscript.exe.)

Figure 3 shows part of the output from running the Win32_OperatingSystem class script in Figure 2. As you can see, the script retrieves and displays the values of the class's properties. However, the output might not include all the properties. The output doesn't include properties whose values aren't set. And if you're using the initial release of Scriptomatic, the output won't include properties whose values are stored as arrays. The first release of scriptomatic.hta (which has a date stamp of August 9, 2002) doesn't support properties of type Array. If the Scriptomatic script encounters an array, it tries to echo the value of that array and fails. However, because all Scriptomatic scripts start off with VBScript's On Error Resume Next statement, this error isn't fatal. Instead, the script simply moves on to the next line. Thus, although Scriptomatic exposes properties that return arrays, the script doesn't return any array values. Microsoft addressed the array limitation in the second release of scriptomatic.hta (which has a date stamp of November 6, 2002). However, this release is available only on the CD-ROM that accompanies the Microsoft Windows 2000 Scripting Guide. Scriptomatic 2.0 (which is actually the third release) will also support arrays.

Scriptomatic 2.0, which is scheduled for release later this year, offers other improvements as well. For example, this new version will let you choose which computers to run the tool on, let you select the language you'd like to use (Perl and JScript will be options in addition to VBScript), and let you select the output format. Scriptomatic 2.0 will also show you all classes in all namespaces.

Collecting Property Information
How can you use the information you gather with Scriptomatic? For starters, you can use it to track down the properties and their values. For example, Windows Server 2003 has a number of WMI providers not found in previous versions of Windows. One of them is the Terminal Services WMI provider, which lets you access Windows 2003 Terminal Services settings. Suppose you want to create a script that changes the default location of each remote computer's home directory. The Terminal Services WMI provider includes 18 classes of objects related to Terminal Services, including

  • Win32_Terminal
  • Win32_TerminalService
  • Win32_TerminalServiceSetting
  • Win32_TerminalSetting
  • Which class contains the setting you want? To find out, you could open all 18 classes in WMI CIM Studio and read through each class's property values. However, it's much easier and more reliable to use Scriptomatic. For each class, you simply generate and run a script, then scan the displayed property information. A quick perusal of the Win32_TerminalServiceSetting class script's output reveals that this class has a property called HomeDirectory, which specifies a computer's home directory.

       Previous  [1]  2  Next 


    Reader Comments

    You must log on before posting a comment.

    If you don't have a username & password, please register now.




    Top Viewed ArticlesView all articles
    Command Prompt Tricks

    One reader shares his tip for setting up the command prompt to reflect a remote path. ...

    How can I stop and start services from the command line?

    ...

    PsExec

    This freeware utility lets you execute processes on a remote system and redirect output to the local system. ...


    Windows OSs Whitepapers Why SaaS is the Right Solution for Log Management

    Related Events Check out our list of Free Email Newsletters!

    Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

    Best Practices for Managing Linux and UNIX Servers

    Building an Effective Reporting System

    Related Scripting Resources Become a VIP member of the Windows IT Pro community!
    Get it all with the VIP CD and VIP access. A $500+ value for only $279!

    Subscribe to Windows IT Pro!
    Solve your toughest technical problems with our experts and access 10,000 + articles online. 30% off

    Monthly Online Pass - Only $5.95!
    Get instant access to 10,000+ articles from Windows IT Pro Magazine!

    TechNet Virtual Labs
    Evaluate and test Microsoft's newest products.


    Windows IT Pro Home Register FAQ for Windows WinInfo News
    Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
    SQL Server Magazine Office & SharePoint Pro Windows Dev Pro IT Job Hound ITTV
    IT Library Technology Resource Directory Connected Home Windows Excavator Windows SuperSite 
     
     Windows IT Pro is a Division of Penton Media Inc.
     Copyright © 2008 Penton Media, Inc., All rights reserved. Terms and Use | Privacy Statement | Reprints and Licensing