What scripting languages are useful in Windows?

Windows has 3 built-in solutions to consider:

  1. PowerShell
  2. Windows Scripting Host
    a. VBScript
    b. JScript
  3. Batch Files

PowerShell (v2.0)

As of Windows 7 and Server 2008, it's reasonable to consider PowerShell as it ships with Windows and is also fundamental for administering server software such as Lync and Exchange. There is a growing list of features available; see Script Center for details.

Windows Scripting Host

Windows Script Host (WSH) is technically a scripting host for ActiveX Scripting Engines. VBScript and JScript (Microsoft's implementation of JavaScript) are the two engines installed by default. Many others are available from the open source community, including Perl, PHP, and Ruby.

VBScript

Using similar syntax to VB6 and VB.NET, VBScripts lack easy access to .NET classes (Powershell is written on .NET so it has access to all the .NET functions). VBScript mostly takes advantage of the WMI service and the objects it exposes.

Example: creating a restore point.

Set wmi, whatName, errResults
wmi = GetObject("winmgmts:\\.\root\default:Systemrestore")
whatName = InputBox("Enter a name for the Restore Point", WScript.ScriptName)
errResults = wmi.CreateRestorePoint (whatName, 12, 100)
If errResults <> 0 then
    Wscript.Echo "Error " & errResults & " : Unable to create Restore Point"
End If

JScript

The same script can be written using ECMAScript:

var wmi = WScript.GetObject("winmgmts:\\.\root\default:Systemrestore");
var whatName = WSHInputBox("Enter a name for the Restore Point", Script.ScriptName);
var errResults = wmi.CreateRestorePoint(whatName, 12, 100);
if(errResults != 0) {
    WScript.Echo("Error " + err + " : Unable to create Restore Point");
}

Command Batch Files

There is of course the good ol' Batch File. They need no intro.


I still write DOS batch files, even in Windows 7. For most tasks, this still works quite well, and it's very simple to work with (also, many of the DOS commands such as "FOR" have been improved over time and provide more options and functionality that weren't available more than a decade ago).

For me, a DOS batch file is still the main scripting language for Windows (it certainly is traditional), but everyone has needs and preferences that differ. There are many things that DOS batch files can't do (scripting languages can pose limitations too), and for the rare occasions where I've encountered this I then look at what my other options are (often it's Perl, or sometimes it could be to write a small program or an entire application).

Understanding what you need to accomplish is a very important step in deciding which tools to use. Familiarity with the tools is another important aspect that can limit your options. If you're trying to decide which scripting [or programming] language to learn, then hopefully this will be helpful to you.


That depends on who you ask. Some will never leave batch, some love vbscript some love powershell, others like AutoIt. Then there are the platform independent ones like Python and Perl that some will swear by for everything.

Tags:

Windows

Script