Best way to automate tasks in windows - windows

Mac has applescript 'built in' and I've found its pretty nice to work with for automating stuff.
What's the best windows equivalent?

Maybe PowerShell -- but it's really much more powerful than applescript. VBA only exists within specific applications that supply it, such as Excel, not stand-alone.

VBScript and JScript are standard Windows Script Host languages. See Microsoft Windows Script Technologies.

I discovered python when I moved to a PC and was looking for something to do all the kind of stuff I'd usually do with applescript. As someone who learned most of my programming skills using applescript it came pretty easily to me. Best thing is that you can use it on any platform.
BTW applescript has been around a lot longer than OSX.

Powershell is the program to learn if you want to automate stuff in windows. Microsoft is deprecating vbscript, which is part of Windows Script Host, and pushing Powershell as the modern replacement for vbscript. For example, Microsoft is creating more and more APIs for Powershell. On the other hand, vbscript bears a great similarity to vba, which is the default program for automating Word, Excel and Outlook.

Just for completeness, there is also the rather dated AutoHotkey. Originally designed to provide system-wide hotkeys to automate things, it can also be used as a general automation tool.
However, I cannot recommend it. The syntax is horrible and obscure, and that's the reason they are currently doing a complete haulover for version 2.

Related

Simple Win GUI - should I try PowerShell or just stick with HTA?

knowing what PowerShell can do on a command line I have never learned how to write GUIs with it. Should I?
Or just go back to the good old HTA / VBScript?
You're sure to get varying answers on this depending on folks' background. I do development work and I'd just as soon write a GUI using C#. The Visual Studio forms designer is quite nice and doesn't have an equivalent in PowerShell out-of-the-box. And the VS debugger is still much better. That said, if you want to delve into this area you should check out two PowerShell modules for creating GUI via WPF: PowerBoots by Jaykul and WPK in the PowerShellPack by one of the PowerShell team members. As you will see when you look at the PowerBoots site, it is definitely possible to do GUI with PowerShell.
I would recommend a simple VB.Net / C# WinForms app.
If you're looking to package Powershell with a GUI I would suggest looking at PrimalForms to quickly prototype your solution.
It has a simple winforms designer powered by powershell scripts.

Programming a terminal emulator, what's in it?

This is related somewhat to this question about a better shell terminal/gui-interface for cmd.exe
In my quest to find a better shell terminal, the only useful thing I came across was Console2, other alternatives weren't free and generally didn't offer much more than Console2 to make them worth their price.
I can't help but wonder, "how come"? The shell terminal is a very valuable tool to a programmer, yet no one came around to try and do a better job than cmd.exe (except for the guys # console2)??
Surely designing a command line shell terminal emulator can't be such a hard task!
Has anyone tried writing a shell terminal emulator before? What's in it? Any resources out there (say, if I want to program my own shell)?
UPDATE
17/07/2009
I rephrased the question, what I was referring to as a "shell" is actually called a terminal emulator (at least in the linux world). I only realized this recently so I thought I should revisit this question and fix it.
There are plenty of shells around for Windows, bash under Cygwin is the one I use the most, and it's certainly free. I have to be honest here, cmd.exe has come a long way since the batch file processor of MSDOS. It's actually quite powerful, but still not a pimple on the rear end of bash :-).
You should try to write a command line shell, it will be an education for you. It's not that hard to do the basics if all you want is a program launcher.
But, if you want all the power of a real shell, including a full blown programming language, job control, piping, output redirection and (seriously) too many other things to list, we probably won't be hearing from you for a while. Except when you pop up your head to ask us esoteric questions about how shells should do this or that.
What about PowerShell from Microsoft? AFAIK it's free, and gives you C# power right in the shell, and tons of other features. But, it DOES require the NET Framework...
I won't endorse it yet, as I haven't really used it, but it's on my list to do...
My bets are on Powershell for the future if you are a Windows guy.
PowerShell will be installed by default on Windows Server 08 R2 (WS08R2) and Windows 7 according to MS.
I have used Powershell myself and found it to be very useful, and if you are familiar with .NET then its all the more easier.
Download a two page reference document here, this is all you will need to get started.
I mean the gui-interface part that displays the text,
Ah! you mean what we call a "pseudo-tty" or a "terminal emulator" in unix. In windows, I guess it is called a "console host". I do not use windows, but I heard that console2 is very good.
Seems there are others:
http://www.powershellanalyzer.com/
http://powershellide.com/
http://www.codeplex.com/PoshConsole
and, of course, for real programmers, you have the shell mode of (x)emacs :-)
Erm... what about all the ports of Unix command shells to Windows?
Just go with cygwin and log on using PuTTY. So much better than the standard console. :)
Also, Python (or perl for that matter) can replace the shell entirely.
You might want to try Take Command Console, formerly 4NT, formerly 4DOS.
Quick summary of points you might care about:
Command line editing with filename completion, history, and cut & paste
Integrate PERL, Ruby, REXX, Python, and any Active Scripting language
Fast - 20-200% faster output display than the standard Windows console
Integrated file explorer - examine directories, drag and drop files
Upwardly compatible with CMD.EXE with literally thousands of additions
Not free (except trial version) and not open source. I haven't tried it myself, but I was a 4DOS junkie back in the day, before Cygwin.
If you need handy terminal - give a try to ConEmu (I'm the author). It is a Windows console window enhancement (local terminal emulator), which presents multiple consoles and simple GUI applications as one customizable tabbed GUI window with dozens of features.
Another answer and comments

Best "official" scripting language for Windows programmers [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
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:
What Is The Best Scripting Language To Learn?
Which Scripting language is best?
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:
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
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 :P
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:
Progress, b2 m, ACME App, Doing some magic...
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).
I pretty much make the case here:
http://mikesharp.wordpress.com/2011/04/03/jquery-for-administrators/
Some highlights:
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.).

What tools and languages are available for windows shell scripting?

I want to know what are the options to do some scripting jobs in windows platform.
I need functionality like file manipulations, registry editing etc. Can files be edited using scripting tools?
What other functionality does windows scripting tools offer?
Can everything that can be done using the Windows GUI be done using a scripting language?
I think Windows PowerShell from Microsoft is the current favourite for this sort of thing.
It might be worth looking at the prerelease of version 2.0. A lot of stuff has changed:
http://blogs.msdn.com/powershell/archive/2007/11/06/what-s-new-in-ctp-of-powershell-2-0.aspx
How about installing a windows version of Python, Perl or your favorite language? These should offer all the functionality you need.
Batch files are the most portable, but doing complicated things can get hard (very hard).
Powershell is incredibly - um - powerful, but the installed domain at the moment is only slightly more than those people who like using powershell and servers they administer. If you control the machines you're scripting on and can mandate that powershell is installed, powershell is the way to go. Otherwise, batch files are the best way.
Powershell lets you do anything which can be done, but some things will be harder than others :)
(Seriously, if you want to control a windows GUI app from a script, you're going to have a lot of pain unless the app supports scripting itself, or you want to start posting messages to dialog controls and screen scraping the dialog to check for success.)
I would recommend "Take Command" (JPSoft), which is more like "cmd.exe" than the PowerShell. We use here at ESSS for years.
Windows Scripting Languages
Also take a look at PowerShell
CScript ? I remember seeing something like that.
Powershell is nice, but it's an extra thing you have to install. Not standard in almost any windows installation. So, if it's just for your own use, then powershell should be fine. If you need the scripts to run on the computers of the general population, for instance, as part of a piece of software you are producing, it may not be the best option.
If you are ok with an extra thing you have to install, you might want to check out cygwin. This allows you to have a full Linux bash command line and all the associated tools at your disposal.
If you need something included in a default windows install. There's the windows command line (cmd.exe). Which has some functionality, but is very deficient compared to what's available in Linux. The other, probably worse problem, is that there isn't much out there in the way of documentation.
You might also be interested in VB Script (flame away). VB Script should work on almost any recent standard windows install, and is a lot more functional than the command line.
I have cygwin installed, so I can run bash shell scripts for my automatization needs. Besides, when I need stuff running moreless natively on Windows, I use a combination of batch + jscript (runs on cmdline if you have Visual Studio.Net installed, just call "cscript XXX.js").
Scripting is a blast.
Personally I like to write some evil little batch files. You can find a command line program to do just about anything. I prefer Batch files mostly because they are portable from one machine to another with at most a zip with a few unix tools (SSED, GREP, GAWK). there is a commandline REG.Exe that can even do Registry changes and reads. You can parse output from commands with a "FOR /f" loop.
PowerShell does have more... err.. Power (2nd post I wrote that in, but I can't help it.)
If you want to look at windows automation check out AutoHotKey.
What are you trying to automate? That may help us narrow down what would be helpfull.
Josh
EDIT: for the record I typed that at the same time as #jameso If someone at work hadn't asked me a question, I may have posted before him. I did get a bit of a shiver at the similarity of the post though....
Powershell can do what you need.
file manipulations
This SO post answers how you can replace a string in your text file. Pasting it here for easy reference:
(Get-Content c:\temp\test.txt).replace('[MYID]', 'MyValue') | Set-Content c:\temp\test.txt
There are other things that you can do, such as copying files and folders. You can find out more on the Windows Powershell Documentation
registry editing
This can be easily done using Powershell. Here's a sample code from Microsoft Dev Blogs:
Set-ItemProperty -Path HKCU:\Software\hsg -Name newproperty -Value anewvalue
Yesterday I could have repaired this for you ;)
What all are the tools/languages for
windows shell scripting?
Would read better as
What tools and languages are available
for windows shell scripting?

Easy installation method for windows/ Batch Reference needed?

I have a bunch of files that I need to be able to transport and install quickly. My current method for doing so is moving a flash drive with a readme file of where stuff goes whenever I need to move stuff, which is rather inelegant and cumbersome.
My idea for a solution would be to write up a quick script to move files around that I could just click on. I've done some bash scripting before but batch scripting is a little odd to me. Does anyone have a good online reference guide I could use?
An alternative soulution I could accept would be a program that makes an installer for you, though I'm a bit against that as I would lose a lot of control. However, I'd be alright with it if it was extremely simple,
Sounds like robocopy tool is exactly what you need.
Very powerful replication command-line tool.
MS TechNet reference,
Wikipedia article about robocopy,
Full command switch guide,
Batch scripting guide.
I like to use VBscript for this kind of thing. The VBS engine is on every recent windows machine and the language is a little more like real programming than a batch script.
Also, if your installer grows to require WMI functions too, this becomes a piece of cake.

Resources