Scripting in Windows

Tags:

Many people probably know Linux and its various easy to use scripting languages, like Python, Perl and Bash Script.
They are available on most systems, and it’s very easy to write little command-line scripts with them to ease various tasks.

Often you could use a small scripting language like the above on Windows, and sure, it is possible to install a parser for Python for example on Windows. But what many people don’t realize is that Windows actually does have built-in scripting support, known as Windows Scripting Host, which is also very powerful!

Supported languages

Windows Scripting Host (WSH) supports “active scripting” engines. By default, you can run JScript and VBScript files, and with additional engines you can install support for other languages.

As you might’ve guessed, JScript is basically JavaScript and VBScript is like Visual Basic. If you’ve programmed in VB, you will be quite familiar with WSH as VBScript is very similar and does things in the same way, for example by utilizing ActiveX.

Despite its image as a toy language, Visual Basic (and VBS/JS) is a quite powerful and useful language, especially when you need some quick to make tools.

Useful or not?

For various sysadmin tasks, WSH is a powerful tool. It can perform any task you would try to do with better known alternatives, like the aforementioned Perl.

One useful task which I’ve simplified is calling some command line utilities. Since WSH scripts support drag and dropping files on top of the script, it’s quite easy to create a script, which runs a specific utility on the files that you drop on it.

I also used to have a list of movies I’ve seen in a file, listed under some categories and such. I wanted to count how many movies were on the list, but counting them by hand would’ve been tedious and if I ever added a new movie, I might need to count them again and so on. However, with a simple VBS, this problem was gone, as the script could easily parse the file format and perform the counting for me.

Another quite useful script I wrote for a friend was a script which would either run Media Player Classic and play the file as its parameter or if it was already running, append the file passed as the command line parameter to its playlist. This was so that instead of always opening MPC with an empty playlist, it would be easy to queue more than one file by just opening more than one file.

In closing

Whether WSH will be useful to you or not is, well, up to you. Just keep it in mind next time you run into some task which would be easier automated! :)

You can find a lot more information, including sample scripts, at MSDN’s Scripting pages