Tuesday, January 30, 2007

Your WSH is my command, part 1

Several recent projects converged on a single need to automate basic server tasks, such as synchronizing folder contents, media conversion, etc. My first priority was to pull special "promo" audio files off of our Content Depot storage receiver and put them in another safe location so that our staff could edit them or otherwise use them in their spot production without having to navigate the critical parts of the storage receiver file system. The Windows Scripting Host (WSH) is ideally suited to automating such tasks. It is installed on every Windows XP and Server computer, is easily scripted and very powerful. In fact, there are several useful scripts included on your installation in the System32 directory, scripts that can automate printer management and filter event logs. I know what you're thinking, though. "VBS files are bad! They are viruses! That's why Norton blocks them!" They can be used by attackers, commonly in email, but are very useful for many Windows tasks. The Microsoft Technet journal carries a regular column called "Scripting Guys" that details many excellent scripting uses. You can also find VB scripts at the heart of the Samurize desktop widget software.

On to the fun stuff, though. As I mentioned, I wanted to get promos off of the storage receiver and into another folder on a different computer where they could be safely operated on. Using VBScript and the WSH, I created a list of files in the source location that match a regular expression, check that they are newer than files in the destination or don't exist in the destination location and copy them. This script then runs on an interval using "Scheduled Tasks" in Control Panel. I also found that using the command line Mplayer software, I could automate the conversion of these files to uncompressed wav files in the destination. Sweet! Lastly, I check to see if there are any files in the destination that aren't in the source location. These are deleted from the destination and walah! We are synchronized!

This type of scripting would also be useful for retrieving many other types of files from the storage receiver, items like images, rundowns, etc. that at this time are locked away because no one wants their staff monkeying around in that folder looking for these files. They could be automatically emailed or pushed to a web server or content management system for use. The WSH makes it easy to automate.

I am including a link to my script for your examination. In part 2, I will show you how I used a script to retrieve and report on the Cartchunk data stored in the wav files.

MSDN Reference Material for WSH

No comments: