You are on page 1of 4

Create Automation Scripts For Windows

With AutoIt
There are plenty of automation tools for Windows. You can use the built-in Task Scheduler to
schedule tasks, or use Folder Actions to set up events for folders. If those are not enough for
you and and you prefer to use a more complicated and powerful automation tool, AutoIt is a
useful tool for you to create automation scripts.
AutoIt is a scripting language which is more powerful than batch scripting and can automate
almost any kind of task in Windows.

Getting Started
AutoIt is not a complex scripting language. If you have some programming knowledge, you will
be able to pick up AutoIt very easily. It will take a while for you to be familiar with the syntax,
but once you get it going, you will be able to make use of it to automate repetitive tasks and
create other programs that work in Windows.
First of all, you will need to download the AutoIt installer and install it in Windows. The default
installation of AutoIt comes with a lite version of SciTE editor, which you can use for creating
basic scripts. If you require more advanced functionality, you may need to download and install
the complete SciTE editor.
AutoIt documentation is also available online. It includes (almost) everything you need to know
about AutoIt language.
Below, we will show you a few examples of what AutoIt is capable of doing:

Automating the launching and closing of
applications
To launch an application, use the Run command in AutoIt:
Run( "program.exe", "c:\program path")

You can also run the application with different user credentials with the RunAs command. If you
want to wait for a particular application to close before launching the next one, you can use
RunWait command.
To close an application, you can make use of the ProcessClose command.
For example, to close Firefox:

Proceed to the next screen Send (!c) . we will be using the shortcut keys to go through the setup process. "text") When the window becomes active. including the installation of application.exe") if $pid then ProcessClose ($pid) Automating program installations The beauty and power of AutoIt is that you can automate virtually anything in Windows.exe") . Usually the keyboard shortcut is denoted by an underline letter.Accept the license agreement Send (!a) . AutoIt can do this very easily. "setup") . you will need to run the setup installer first by using the Run function: Run ("setup.Install Office with default options WinWaitActive ("Microsoft Office Professional Plus 2010".Wait for the setup window to be active WinWaitActive ("Microsoft Office Professional Plus 2010". WinWaitActive ("Window title". For example. simply send Enter: Send ("Enter") And when the installation is complete.exe") Then we need to wait until the interface appears on the screen. Run ("C:\path\setup. Basically. you can close the window by using WinClose function. "Choose the installation you want") Send (!i) . If you are a network administrator and want to automatically install programs silently without user intervention.local $pid = ProcessExists ("firefox. Most of the installers allow you to use keyboard shortcuts to proceed with the installation process. Send ("!a") And when you only need to press the Enter key.exe") You can also give full path of the program if it is not in the current directory.Run the Office 2010 installer Run ("setup. We can use WinWaitActive function for this purpose. the script will look like this: . so you will need to press “Alt” and the underlined letter for action. to automate the installation of Microsoft Office. you can use the Send function for processing the keyboard shortcut. In AutoIt.

The macro recorder will record all your keystrokes and then simulate those keystrokes when the script is run. The Macro recorder is available in the full version of SciTE editor. we don’t need to run the WinClose function.. for numerous reasons. . The only limitation of the macro recorder is that we don’t get WinWaitActive function inserted automatically between each keystroke. The second command checks to see if the window is active and if it isn’t. AutoIt is much more powerful and can perform the most tedious tasks very easily. It is important to include WinWaitActive function otherwise the script will complete its execution even before the first setup screen appears. activates it so that the WinWaitActive function sees it and allows the script to carry on. "Setup Complete") Send (!c) Since the installer will automatically close after installation. “text”) Then WinActivate(“title”. “text”) WinWaitActive(“title”.” While you are correct in the reason for using the WinWaitActive function. Conclusion While there are several other ways to automate programs and tasks in Windows. “text”) If Not WinActive(“title”. What should be used is the following: WinWait(“title”. Creating Macros What makes AutoIt even better is the Macro recorder which can be used for lengthy and tedious sequences of keystrokes.Close the setup when office is installed WinWaitActive ("Microsoft Office Professional Plus 2010". To access the Macro recorder. never become active. “text”) The first command waits until the specified window appears.  “It is important to include WinWaitActive function otherwise the script will complete its execution even before the first setup screen appears. causing the script to wait forever (or until it gets cancelled). there’s a problem with using just that function by itself: the window being waited for could appear but. open SciTE editor and go to “Tools -> AU3Recorder” or simply press “Alt + F6″ shortcut key.

This is an efficient programming style. then all that is indicated is that the macro is waiting in the new function. and then puts a call to *that* function in each place that the macro has to wait for a window. in which you don’t have large blocks of code repeated numerous times throughout the source file…it comes from a time when programmers had to keep their source files as short and tight as possible in order to keep the programs themselves as small as possible. you have no idea what it’s waiting *for*…which makes it difficult to fix the problem. The only reason I don’t like this new way of using WinWaitActive is that if debugging is turned on. . If you weren’t watching carefully.“The only limitation of the macro recorder is that we don’t get WinWaitActive function inserted automatically between each keystroke” Are you sure? The version of the recorder I currently have installed (admittedly a little old) doesn’t put the WinWaitActive function itself in each place the macro has to wait for a window but instead puts the 3 lines I have above into a function at the beginning of the macro.