Contents for Guy’s Scripting Ezine 34 – Scriptomatic
This Week’s Secret is a utility called Scriptomatic. Here is a wonderful program from Microsoft which will extend your scripting techniques. What Scriptomatic does is to help you analyse and dissect objects such as users, computers, or even the operating system itself.
Scriptomatic has those twin hallmarks of a great utility, it automates repetitive tasks, and teaches you more about scripting methods. Most of all, Scriptomatic saves you having to grapple with that tricky WMI syntax What you see there in the interface are all the VBScript commands laid out perfectly; all that remains is for you click ‘Run’. Merely inspecting that list of options is bound to generate ideas for your own scripts. As ever, I will give you examples to get you started.
Scriptomatic is an .HTA file which connects to the operating system and then displays information on Win32 ‘classes’ such as, UserAccount, DiskDrive or even the BIOS. HTA files are a cross between HTML and VBScript; if you wish, you can inspect Scriptomatic.hta with Notepad or your favourite HTML editor.
Once you have obtained a free copy of Scriptomatic, just double click to execute. As the .HTA file runs, you briefly see a dialog box with ‘Loading WMI Classes’. This means that the script uses the Windows Management Interface to interrogate the operating Win32 classes. In plain English, Scriptomatic gives you a handle on objects such as; user, disk or network adapter.
When you have selected which class to investigate, you can either, click ‘Run’ and instantly see the output in a ‘Dos Box’, or else save to a .vbs file and run that script to produce a WScript message box. The good news about Scriptomatic is that it outputs just about every property that can be scripted. The bad news is that you become swamped with data. So the key is to be ruthless and delete unwanted lines or elements before you run the script.
Beware: If you run the raw .vbs scripts without editing, then you will be overwhelmed with data, so get ready with Task Manager, Processes (Tab), wscript.exe (Image Name) right-click – end process. Or else you may have to press the enter key 20,000 times. (So I exaggerate, but a run-away script can be a tiresome.)
Warning: For once, I would not, repeat NOT, run the Example 1 script. Just admire its methods, then compare with my modifications in example 2. If you do run Example 1, then get ready with Task Manager – End Process.
On Error Resume Next
Guy Recommends: The Free IP Address Tracker (IPAT)
Calculating IP Address ranges is a black art, which many network managers solve by creating custom Excel spreadsheets. IPAT cracks this problem of allocating IP addresses in networks in two ways:
For Mr Organized there is a nifty subnet calculator, you enter the network address and the subnet mask, then IPAT works out the usable addresses and their ranges.
For Mr Lazy IPAT discovers and then displays the IP addresses of existing computers. Download the Free IP Address Tracker
Here below, is the script that I do recommend you test.
Whilst Scriptomatic is fantastic, it benefits from fine tuning. My main idea is to produce one WScript message with 17 entries in one box, rather than 17 boxes each with a one line entry.
Modifications in Example 2
& VBcr This joins or concatenates a carriage return. The result is a new line for each item.
_ (Underscore) this tell the script there are more statements on the next line, note the use of ampersands (&).
Tip. What I did was a Find and Replace. Find = WScript.Echo, Replace = & VBCr _ &. Then I made adjustments to the end of line with carriage returns and deletes.
I love the construction: If Then… End if, here I use the ‘If Then command’ to filter just the administrator, rather than repeating the message box for each of my 500 users.
‘ ScriptomaticAdmin.vbs – Enumerates the Administrator’s properties
Note 1: strComputer "." means THIS COMPUTER.
Note 2: Here is where Scriptomatic earns its corn and connects to Windows Management Interface.
Note 3: the ‘col’ in colItem means collection.
Note 4: objItem.Domain The word after the full stop is a property, for example .domain .fullname or .installdate.
Note 5: Select * from Win32_UserAccount. In another script, for a different purpose, Scriptomatic could change this line to: Win32_Bios or Win32_DiskDrive.
Note 6: An old friend ‘GetObject’ and a new method ‘ExecQuery’
Cut out unwanted lines. For Example delete:
An obvious modification would be to change Administrator to another user.
Note: The last line has a different ending (there is no & VBCr _)
I have merely scratched the surface, given you one example of a familiar object – a ‘user account’. There are zillions of other classes that you could have selected within Scriptomatic’s drop down box. More often than not, the raw Scriptomatic code can be improved by replacing some of the echo statements with VBCr.
Scriptomatic is a ‘must’ utility for building up your collection of VBScripts. Learn about the objects, methods and syntax of VBScript while you explore the WMI classes.
See more about VBScript