Scripting language in windows

What scripting languages are useful in Windows? [closed]

What scripting languages are useful for Windows automation?

9 Answers 9

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.

JScript

The same script can be written using ECMAScript:

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.

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.)

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.

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.

Читайте также:  Как узнать свой герц монитора windows 10

A scripting language for Windows? [duplicate]

I work in Windows and often find the need to code some script that manipulates files or basic string manipulation. Currently, I’m doing this using PHP but having a LAMP stack for this seems overkill. I’ve tried things like autoHotkey but the syntax and functionality is horrific.

So I’m looking for a scripting with: a) a sane syntax b) lots and lots of built-in libraries, functions, etc c) minimal setup. Preferably, I would like to code and run the script from my app launcher of choice, Executor

8 Answers 8

Windows PowerShell™ is a task-based command-line shell and scripting language designed especially for system administration. Built on the .NET Framework, Windows PowerShell™ helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows.

The Microsoft Windows Script Host (originally called Windows Scripting Host, but renamed for the second release) is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported features.

Mafutrct has provided a very good response; if you are starting windows scripting then you should definitely begin with PowerShell. The built-in commands, PowerShell extensions and the ability to use the .NET runtime ensure that all your scripting requirements are met. I only wish for a better scripting language in PowerShell. If only it were Javascript :(.

I want to point out that WSH remains a viable scripting environment for windows. The reasons why I continue to use it are:

  • Javascript, being both functional and prototypal, allows complex scripts to be written simply and easily
  • Throw in WMI and almost everything windows related can be accomplished very easily. This is very useful for networking and system administration tasks
  • WSH scripts can be run with equal convenience on both window and console (i.e. invocation by wscript and cscript)
  • Writing a script is as easy as opening notepad, typing the script, saving it as a js (or .vbs, .wsh) file and double clicking the saved file
  • Although it no longer remains strictly a script, a .js file can be complied for the CLR using the .NET’s Javascript compiler: jsc.exe. Like PowerShell, this provides access to the entire .NET framework

Some of the scripts that I wrote in the last few weeks were:

  • Pulling data from MS SQL server, creating an Excel sheet and pushing the data into it, and mailing it to a client
  • Formatting, parsing and filtering thousands of lines of VOIP switch log files and vector scripts
  • Using Ajax to pull data from a remote server, calling a web-service and passing the data to it

I spook my co-workers when they use my laptop by remotely “speaking” to them via the speakers with a script using Microsoft’s Speech API. Here’s the sample code:

Best “official” scripting language for Windows programmers [closed]

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

Closed 7 years ago .

Suppose there were several projects mostly maintained by smart interns, who eventually leave after a period of time. Scripts are used here and there in key parts, for example, to back up a database, rename it, zip it, move it over ssh, unzip it, and then to restore it with different settings. You know, the scripting stuff.

The programming languages for the application side is set, but those for scripts have been relaxed. Currently there are probably healthy mix of bash and .bat file, and maybe some Perl.

1) To avoid language proliferation, and 2) because I don’t want to force bash upon future Windows programmers, I’d like to set an «official» scripting language.

Google picked Python for this, and it’s famous for being readable, easy to learn, and having good library; however, I personally don’t find it that readable compared to C-like grammar, Pascal, or Ruby.

In any case, if you were to be forced to use only one scripting language on a Windows machine (with Cygwin if you want to) for all scripting, what would you like it to be, and why?

Related religious wars:

8 Answers 8

PowerShell — designed from the ground up to be a Windows scripting language, and it can hook into the CLR for advanced functionality.

(yes, I realize this doesn’t run under cygwin. but why is that a requirement?)

When I’ve written cross-platform product installers, coding a UNIX shell script for Linux/Mac/Solaris etc. is really easy, but trying to do equivalent tasks in BAT is like working in the dark, underwater, with both hands tied behind your back. I can’t state strongly enough that BAT scripts are a blight on humanity.

So what I’ve heard about PowerShell makes me happy. It’s a life-saver for Windows developers. The only trouble is that I believe it’s still a separate install, it isn’t available by default (I’ve read that it’ll be on Windows Server 2008 and Windows 7).

Oh well, it only took Microsoft 20 years to replace BAT scripts with something as capable as UNIX shell, so I guess I shouldn’t be too ungrateful! >:-P

Get the installer for PowerShell here:

I’ll try to provide an alternative — JavaScript and VBScript work fine too even on Windows versions long gone, and they don’t need a seperate installation like PowerShell. 😉 Of course, PowerShell has more power 😛

I’d urge you to give Python a chance. It looks a little odd to ‘C’ programmers at first, but its easy to pick up and more importantly easy to remember. You are going to have interns of various skill levels using and modifying the code so you want something that can draw from a wide user base. And if you are going to go to the trouble of installing something new why choose powershell which is going to be a dead end for anyone using it.

Powershell. It’s got the breadth and the depth, and is fully supported (now and in the future.) Unlike Cygwin, for instance.

The best scripting language I have come across for interface and control type applications in Windows is AutoHotKey. Anyone developing on windows should learn about this language. It can save you an enormous amount of time just automating retarded windows tasks.

One of the most useful tools I have come across for Windows is Texter

This utility is written in AutoHotKey and saves me from having to type anything more than a few times. An indispensable tool for a coder or anyone filling in forms or tickets.

If you are like me and want to display nifty progress bars or splash screens while your script is doing it’s magic (instead of a black/gray command prompt window), use AutoHotkey. Showing a progress bar is a PITA with JScript/VBScript (WSH) and/or PowerShell from what I’ve found. In AHK it’s as simple as:

Also you can interact with almost any control in any window and automate apps which are not meant to be automated.

For your particular description, PowerShell sounds like a good way to go . but I would make a strong case for JScript under WSH (or JavaScript under Rhino/etc.). Sounds like you like CYGWIN, but Powershell does not currently have support for other platforms (too much native stuff I think — that’s a separate discussion IMO, but Google should answer it).

  • JavaScript is installed by default on every Windows OS after ’95
  • JScript scripts work «out of the box» with Active Directory
  • ECMAScript is an open standard (which JScript is an implementation of)
  • Through ActiveX/COM JScript can do most of what Powershell can do and under Rhino it has the power of Java
  • Can be used to create HTA applications (and later, metro apps with WinRT/HTML5)

JScript doesn’t have direct access to the .NET framework — although there are a few 3rd party JavaScript engines in pure .NET that interpret it and can share objects with it like Jurassic and IronJS. Also wrappers like JavaScriptDotNet (around Chrome/V8). Powershell will likely be faster than JScript under WSH, but the same might not be said of other 3rd party interpreters.

Just please don’t go with VBScript (lacking try/catch, no real OOP, proprietary, deprecated, etc.).

Intro to Scripting Tech on Windows (Compared to Unix)

In 2009, i Switching from Mac/Unix to Windows, after 10 years as a programer and sys admin on the unix environment. This page is my learning notes about scripting tech on Windows.

Here’s a table listing technologies on unix and Windows that have similar purposes.

Unix vs Windows Automation Tech

в—‡ unix Windows Comments
Shell Bash cmd.exe, PowerShell cmd.exe aka batch script is old. PowerShell is new with Windows 7.
Application Scripting AppleScript (OSX) VBA (MS Office) VBA = Visual Basic for Applications. On linux, lang varies depending on the app; typical are Python, Perl, Tcl, Scheme lisp, JavaScript variant.
Advanced sys admin Perl, Python VBScript, PowerShell в—‡
Web Server PHP, Perl, Python Active Server Pages Active Server Pages (ASP) uses JScript (JavaScript) or VBScript (Visual Basic) as langs.
Web Client Side JavaScript JavaScript, VBScript в—‡

What is the difference between Visual Basic, VBA, VBScript, Visual Basic .NET?

  • Visual Basic is a general purpose computer language.
  • VBA (Visual Basic for Applications), is a language embedded in Microsof Office applications for scripting these apps.
  • VBScript is a version for Windows sys admin and web app client-side scripting.
  • Visual Basic .NET is a new version of Visual Basic based on the .NET platform.

They are the same language just differ a bit because of the context. However, they don’t run on the same engine (but they do share the use of many Microsoft’s component tech such as COM and DLL).

The latest version of the classic Visual Basic is VB 6. VB 6 is no longer supported. It is replaced by the .NET version, and it has version naming starting at VB 7 and currently VB 10. However, VB 6 will still be included in Windows 7. VB 6 will probably be around for many years in practice.

What is the difference between VBScript, Windows Script Host, and PowerShell?

  • MS-DOS is a operating system of the 1980s and early 1990s. It is basically command-driven in a text-only display of the time (Monochrome monitor).
  • command.com comes with the graphical OS Windows 95. “command.com” is command-line interface compatible to MS-DOS.
  • “cmd.exe” comes with Windows NT line (late 1990s), and is used in Windows XP, Vista, 7.
  • PowerShell is the next generation of scripting lang. It comes with Windows 7.

Basically, MS-DOS, command.com, cmd.exe are all meant to be the same thing, but with different implementation. This is similar to unix command line evolution sh в†’ tcsh в†’ bash.

Windows Script Host (WSH) is created in late 1990s, because cmd.exe is not powerful for scripting. WSH is bundled with Windows 98. Quote:

The Microsoft Windows Script Host is an automation technology for Microsoft Windows operating systems that provides scripting capabilities comparable to batch files, but with a greater range of supported features.

It is language-independent in the sense that it can make use of different scripting language engines. By default it interprets and runs plain-text JScript (.JS and .JSE files) and VBScript (.VBS and .VBE files). Users can install different scripting engines to enable them to script in other languages, for instance PerlScript. The language independent file name extension WSF can also be used. The advantage of the Windows Script File (.WSF) is that it allows the user to use a combination of scripting languages within a single file.

WSH is just a hosting engine, it needs scripting engines such as VBScript (Visual Basic) and JScript (JavaScript).

In 2006, Microsoft released PowerShell, which is a new shell design based on .NET technology. PowerShell is more versatile and powerful than WSH+VBScript because it can be used interactively as a shell like cmd.exe, and it is also a full scripting lang that are fully integrated with the .NET platform, and can use all .NET libraries. Going forward, PowerShell is a replacement for the whole cmd.exe and WSH bag. PowerShell comes pre-instaled with Windows 7.

What is Active Scripting?

Active Scripting (aka ActiveX Scripting) is more or less a marketing term that MS uses collectively to describe MS’s scripting tech, including JScript, VBScript, ASP (Active Server Pages), WSH (Windows Script Host). Active Scripting is deprecated by MS’s .NET Framework .

In unix, you script using bash, shell tools (For example, find, grep, sed, awk, make), or perl and python. In Windows, scripting are done with VBScript and now PowerShell.

Visual Basic is one of the most important way to script Windows for sys admin as well as writing standalone Windows applications. Its role is similar to Python or Perl, but unlike unix’s scripting techs which are largely all independent, Visual Basic is tightly integrated and dependent on various Microsoft’s component technology to work.

When scripting Windows for sys admin tasks, often you’ll also make use of Windows Management Instrumentation (WMI) and Active Directory Service Interfaces (ADSI).

Meaning of “Shell” in unix and Windows

In unix world, a “shell” refers to the command line interface to the OS.

In Windows, Windows Shell refers to the whole GUI, in particular the file manager Windows Explorer, and taskbar and Start Menu .

The Windows command line interface is called Command Prompt, and the program name is “cmd.exe”. It is to be replaced by PowerShell in Windows 7.

“script” and “batch file”

In unix world, a “script” refers to text file of shell commands or constructs. In Windows, a file of cmd.exe commands is often called a Batch file instead. However, PowerShell or VBScript files are still called scripts.

Terminal vs Console

In unixes, to run a shell, you start a Terminal emulator, which is configured to start bash or tcsh.

(in linuxes, the terminal emulator app is often xterm , and on OS X the program is called Apple Terminal.)

Terminal Emulator or Console are terminologies from the 1970s and 1980’s, and their meaning is a bit fuzzy now. Physical Terminal or Console has been pretty much obsolete since late 1990s. The terms “terminal emulator” or “console” today mostly just refer to a command line app.

In windows, its terminal is called Win32 console, which hosts the cmd.exe and PowerShell.

In unixes, you start the terminal app, which then is configured to automatically start a shell such as bash. In windows, you don’t do that. You start the cmd.exe or powersell process directly. These programs are written with the Windows Console as its interface.

Summary

For scripting tasks on Windows sys admin, you need to know basics of cmd.exe. For advanced admin, you need to master VBScript, which is the bread and butter tool right now. Visual Basic is important because it is among the top 5 most used language. (the top langs include: Java, C, C++, PHP, Visual Basic, C#, Python, Perl, JavaScript) Going forward, you should learn PowerShell, which is included with Windows 7 and posed to replace cmd.exe and VBScript for sys admin tasks.

PowerShell Tutorial

If you have a question, put $5 at patreon and message me.

Читайте также:  Resource module python windows
Оцените статью