# What scripting languages are useful in Windows? [closed]

What scripting languages are useful for Windows automation?

-

## closed as not constructive by Mehper C. Palavuzlar, Joe Taylor, Wuffers, John T, NifleMay 26 '11 at 17:11

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

I gave +1 because I can see an interesting question lurking behind what you wrote. As it is though, I think "main" is an unfortunate word choice that you should edit to make less vague. Perhaps "most commonly used", "best-supported", or "recommended", depending on what you mean. Welcome to SuperUser! :) –  Brennan Vincent May 25 '11 at 6:25
@Brennan Vincent: That's a great suggestion, but changing the word "main" at this point may detract from the spirit of the answers. I think your comment speaks volumes on this matter, and that the question is better left as is. (+1 for you for that, by the way.) –  Randolf Richardson May 25 '11 at 7:35
At the moment I think this question falls into the subjective category. However with a little modification of the wording as Brennan suggests I think it could be quite an interesting community wiki entry. –  Joe Taylor May 25 '11 at 11:06
Looks subjective to me, also. For scripting languages, "main" or "best" or "preferred" would differ based on the particular task being accomplished, and an individual's skill and experience. –  Iszi May 25 '11 at 12:58
I take the question to mean: what is the native scripting language for Windows today?, ie, what scripting language has built-in hooks and functions into the OS as opposed to requiring APIs, ActiveX, etc. to get things done? –  Synetech May 25 '11 at 13:02

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 ship with Windows, and it is also fundamental to administer server software such as Lync and Exchange as there is a whole set of commands availble for them. 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 other are available as open source, 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 take advantage of the WMI service and the objects it exposes.

Example: This creates 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

You can also write the same script 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.

-
As for Windows 7 and Server 2008, it would be Powershell 2.0 –  sshow May 25 '11 at 9:45
@sshow agree about being specific about 2.0 –  Nick Josevski May 30 '11 at 23:35
"They need no intro." But the do need an extro... –  glenn jackman Mar 27 '14 at 17:16

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.

-
If by "main" scripting language you mean "oldest and most widely used", this is definitely the right answer. However, cmd really is a monstrosity, easily the WORST shell scripting language that I've ever had the misfortune to use. –  JSBձոգչ May 25 '11 at 12:59
I too use batch files when the script needs to be used on other versions of Windows. If you are only dealing with Win7/Server 2008 then PowerShell is the way to go. –  jtreser May 25 '11 at 13:05
+1 I know MS wants powershell to be it, but for now if you want to send someone a script that is running "windows", you have to send them a DOS batch file. PS is great for certain versions of windows for certain tasks and they expose a lot of power, but batch files are universal. –  Alan Jackson May 25 '11 at 14:06

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.

-
+1 for mentioning cross-platform scripting languages (Perl is my favourite, and I know that Python has been gaining popularity over the years too). –  Randolf Richardson May 25 '11 at 18:04
+1 for Perl. It is useful on many platforms and it has some Windows-specific modules. –  RedGrittyBrick May 25 '11 at 22:59
I would add that TinyPerl is a very useful way to embed simple Perl script with not too many dependencies. It will compile to a tiny EXE file on Windows. tinyperl.sourceforge.net –  Benoit Jun 4 '11 at 15:09

I suppose the official scripting “language” for Windows would be (and has been since Win95) Windows Script Host.

Technically, WSH is not a language unto itself, but rather an environment (not GUI) that exposes COM interfaces to allow you use (almost) whatever scripting language you want, to do OS things, even things that have no native way built into the language (for example, Ruby has no built-in way to log into Windows or TCL/TK has no built-in way to show the Run dialog).

You may have seen some WSF files which can include multiple languages in one file, but usually WSH scripts are written in one language and distributed with an extension corresponding to the scripting version of that language (eg VBS for VisualBasic scripts, PYS for PythonScript, etc.)

-
[shuddering intensifies], I used to write that. You know you can run arbitrary WSH scripts from IE? Isn't that quaint. Nice how they open up so much of their api to the web. (Disclaimer, this cynicism is dated by XP-SP3) –  ThorSummoner May 14 at 17:02

I would say AutoIt, it provides very fast and easy developedment on windows and is very tight coupled with it. This means that tasks that usually take rather much code in other languages can be done in literally one line in autoit. Features such as direct compilation to exe's is also very useful.

-
Like monoceres, I use AutoIt. It's extremely versatile for even rapid prototyping and testing concepts in a few minutes. Amongst that, it's designed for automation, which is what I see a lot of people using Powershell for. Give it a try :) –  James May 25 '11 at 16:17
AutoIt is pretty cool, especially for UI functions (acting like a user typing into a dialog box, pushing buttons, etc.) but it would be a real stretch to call in the "main" Windoze scripting language. These days most of my colleagues (in a team of 20+ Windows Admins) haven't even heard of it. –  ewall May 25 '11 at 16:49

The other languages pointed in this question (VbScript, PowerShell, Batch) are very popular and supported. If you already know a scripting language and feel comfortable with - by any mean go with that.

If you are about to invest in picking up a new language, I'd suggest two languages for you, depends on the job you are trying to do:

JavaScript (via WSH) - use JavaScript if you want to use various Automation Object by instantiating them, and calling into their Object Model. You can create an Automation Object for pretty much everything, from Exchange server to WMI to Office documents. There is a debug support with Visual Studio (with the /x argument). Also, an investment in JavaScript will prove to be useful in HTML.

Perl - use Perl if you can to launch other programs, manipulate their output, perform regular expression. Although it seems this language is currently in the decline, it is still a very popular, very well supported with a big community language. You should also consider this language for communicating with other services (not necessarily Windows), such as a JIRA on the enterprise, or EC2 on Amazon. Debugging is supported in eclipse with EPIC, which is also a good IDE environment (syntax coloring, etc.). There are modules in CPAN for everything. Perl knowledge will prove to be useful when having to do automation on non Windows machines.

-
Python is a very good alternative to perl, though the things you'd use the two for are pretty much identical –  Phoshi May 25 '11 at 22:32
+1 for mentioning Perl –  m0skit0 Jun 21 '12 at 9:39

In the early days, there was VBScript followed by Batch, in the corporate environment with pure Windows 7 and Server 2008 R2 the new scripting language Powershell is raising a lot of attention.

-
You seem to be expressing a keen desire for PowerShell to take over. Would it be fair to assume that you "want it to be" PowerShell? ;-D –  Randolf Richardson May 25 '11 at 18:01
I prefere powershell over vbscript yes. –  EKS May 25 '11 at 18:18

I second the recommendation for Perl, if you're up to writing some Perl scripts. People I work with have successfully used and recommend CLR Script (a bit old), and for scripting web interaction,iMacros

-
+1 for recommending Perl. –  m0skit0 Jun 21 '12 at 9:40

It could be almost anything, depending what you try to automate. It will vary from batch files and PowerShell to autohotkey and Selenium (if you need to automate some GUI related tasks).

Usually it is not a problem to learn one, if you need to add some modifications or support already written scripts. If you need develop something new - choose language/way based on requirements, and what you already know.

-