Self-writing code


If you do a lot of scripting for Windows, then you probably use VBScript (VBS) to do it.  With VBScript you can easily retrieve information about pretty much anything that is in your computer, or connected to the network, which is what makes it a good choice as a scripting language.

When working on a project I often need to create a script that will take an action based upon certain criteria.  For example, I recently created a script that renamed the assigned drive letter in Windows Explorer for the CD-ROM drive, only if the existing assigned letter was “E:\”; the best, and surest, way to do this is by including a WMI query in your script and then reading the output.  Most people however get rather lost in the seemingly overcomplicated commands/syntax required to include WMI queries in a VBS script, which although rather daunting to look at, is not actually too difficult to do, especially if you have a tool that does the whole job for you!

The WMI Code Creator from Microsoft is an invaluable tool that you can use to instantly generate sample VBS script that uses WMI.  Simply choose the Namespace you want to use, select the class and then click on one of the properties; in the right-hand pane will appear the example VBS code that you can use.


So why try to work it out by yourself when you can use this free tool to generate all the code you need!  See this page for a full review of the tool and the links to download it:

Also, I thought I’d include links to some other invaluable scripting tools that are often overlooked but are equally as useful:

  • Scriptomatic – Another code generating tool that can help you write your WMI code.
  • Script Center All-in-one – A single .chm file that includes over 160 example scripts.
  • Tweakomatic – Creates the code that will allow you to tweak all those system settings that are not exposed in the Windows default user interface.
  • EZADScriptomatic – Auto-magically creates ADSI VBS scripts that allow you to interact with Active Directory.