Mr. Script

Scripting Tweaks

This tool creates scripts for tweaking remote systems.

As with many things in life, it’s often the little things that make the most difference. Simply ensuring that you keep your DMZ servers updated with the latest security patches may, indeed, be enough to protect from a cyber-attack. With regard to scripting, it’s frequently those scripting techniques that perform tiny little tweaks or small-grained functionality that we use over and over. Sure, we can write some behemoth, but generally, those wind up being one-offs—big projects that require a major investment in time and resources to perform a once-in-a-lifetime critical task that simply had to get done. Conversely, it’s those flexible little spark-plug scripts that find their way into nearly every routine administrative task, for it’s this fine-grained functionality that proves to be truly reusable.

Over a year ago, I introduced the Scriptomatic, a hypertext application written by Microsoft’s Scripting Guys that creates scripts for interfacing with specific namespaces in WMI. These “scriptlets” can then be integrated as needed into scripts. Those crazy guys have come up with another indispensable tool: the Tweakomatic! Like Scriptomatic, Tweakomatic generates scriptlets for performing a specific task. However, as the name implies, these scripts provide much of the functionality found in that ubiquitous Windows powertoy: TweakUI.

One of the first things I do when I get a new computer is run TweakUI. I’ve grown accustomed to a specific look-and-feel in my desktop environment, as well as general computer behavior. Tweakomatic can make these changes remotely via WMI, thus, “standardizing” every computer in your organization.

Here’s an example of a minor tweak becoming a major issue. When I was an IIS admin, all of our servers were kept in a big, secure computer room. To conserve space and maximize efficiency, all these computers were hooked into Raritan KVM switches, allowing access to any computer from a single monitor, keyboard and mouse. One of the challenges in using a KVM switch is verifying that you’re connected to the correct computer. Naturally, we used my Computername tweak to display the username and computername under the My Computer icon on the desktop, but that only works if someone is logged on. We needed a foolproof way to instantly verify that we had switched to the correct machine even if no one was logged on.

The solution was to put the computer name on the desktop wallpaper. This wallpaper was then selected for the Default user, causing it to be displayed on the login screen. It worked like a champ. The point is that, quite often, minor tweaks are all that’s required to get the job done. TweakUI enables this for the local user. Tweakomatic brings this functionality to the remote administrator.

Let’s Get to It
Step one is to download Tweakomatic from the Microsoft site: www.microsoft.com/downloads, then type “Tweakomatic” into the Keywords field.

When you have it downloaded and installed, you can begin creating scripts. Let’s use the example above and create a script to change the desktop wallpaper of the Default User account.

Tweakomatic creates TweakUI scripts.
Figure 1. Tweakomatic creates TweakUI-style scripts that you can run on remote computers. (Click image to view larger version.)

Figure 1 shows the Tweakomatic application open with the appropriate Windows Wallpaper settings selected. It has already created two scripts: one for setting the value of the Wallpaper registry key (executing a Method); and one for retrieving the current setting (viewing a Property). With a few minor edits, you’ll have a working script:

'TweakomaticExample1.vbs
'Change default wallpaper

HKEY_ USERS = &H80000003
strComputer = "."
'Local computer
Set objReg = GetObject _
("winmgmts:\\.\root\default:StdRegProv")
strKeyPath = ".Default\Control Panel\Desktop"
objReg.CreateKey HKEY _USERS, strKeyPath
ValueName = "Wallpaper"
strValue = "c:\windows\WPWithComputerName.bmp"
objReg.SetStringValue HKEY _USERS, _
strKeyPath, ValueName, strValue

Tweaking the Tweakomatic
Unfortunately, the automatically generated script isn’t always ready to go as-is. In this case, you have to make some minor, uh, tweaks. The good news is that Tweakomatic provides the capability of running the script from the Tweakomatic interface, thus, saving valuable time as you refine your scripts. The first change is in the root key. The Tweakomatic script defaults to HKEY_CURRENT_USER. Because you’re changing the wallpaper for the Default user, change it to HKEY_USERS and add the “Default” folder to the key “path.” Finish by pointing to a bitmap that is edited in Paint.exe to add the computer name to the image.

Tweakomatic also allows you to specify the machine name to be used by the script. That way, you can test the script locally until debugging is finished. You can then substitute the appropriate computer name and run the script for real.

This is just one example of a Tweakomatic script. There are many more! You can change Internet Explorer settings and security, command window settings, mouse settings, screensaver and many more. It can’t do everything that TweakUI can (most Registry changes are limited to the “On/Off” variety), but it can do a few things that TweakUI can’t. (For examples, see the documentation that accompanies Tweakomatic.)

In case you missed it, here it is again: The Tweakomatic allows you to run scripts from within its environment. This is the coolest thing ever! Not only is the Tweakomatic a genius at creating scripts for tweaking remote systems, but now there’s finally a replacement for “Visual Notepad.” Granted, it’s not PrimalScript (or even VbsEdit, for that matter), but it’s free and it works. See for yourself. Install Tweakomatic, then copy and paste code from one of your VBS scripts into the script window. Click Run Script and watch it go!

About the Author

Chris Brooke, MCSE, is a contributing editor for Redmond magazine and director of enterprise technology for ComponentSource. He specializes in development, integration services and network/Internet administration. Send questions or your favorite scripts to [email protected].

comments powered by Disqus
Most   Popular