Thursday, May 6, 2010

Creating a batch file...

A batch file allows Windows users to run a sequence of commands automatically, after just double clicking (executing) the file. A batch file is just a file with an extension of ".bat", you can simply edit this file pressing 'edit' after right clicking on the file.

You can find some useful information about batch files, commands etc. from here.

Here's a simple batch file created by me:

cd /d C:\Documents and Settings\NirFLK\Desktop\Project2
auto_aaaBuild.exe C:\Program Files\aaa Applications\aaa.exe
CALL 2.bat
del 1.bat

line 1: Does the job of "cd" in a command prompt. (i.e. switch to the given path) Note: you need to include '/d'.
line 2: Running an exe file with a parameter
line 3: CALL used to execute another batch file within this batch file
line 4: After executing the 2.bat file, this line will delete itself.

Wednesday, May 5, 2010

Do you want to automate a process?

Sometimes we have to do a same set of things manually everyday. Personally I felt some processes are really tedious, so it is really inefficient to do them manually. There's a solution if we can spend some time on coding. To automate a process we normally use scripting languages, eg: shell scripting, AutoIt etc. In this post I will focus on AutoIt scripting language, which I got to know from a friend of mine.

AutoIt is a freeware scripting language which is mainly useful in automating Windows GUIs (it can use for general purpose scripting as well.). You can download AutoIt from here. I suggest you to download the full installation package since there are some other tools (such as AutoIt Window Info tool) other than the editor, which I found very useful.

You can find AutoIt documentation from here. It has nicely documented, and some examples in "Tutorials" section which is really useful to learn AutoIt. List of functions in AutoIt is listed here.

I used AutoIt to automate some GUIs in my training place (#IFS), and at my home to compile, build, and run Derby from source and also to establish a connection to a database in Derby.

I like this because it is easy to use language, and anyone can get use to it with one full day :).

Here is a script to automate the installation of a software (trial version) called PDFAppraiser:

WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Next >")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "I &accept the terms in the License Agreement")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Next >")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Next >")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Install")
WinWaitActive("Apago PDF Appraiser 1.0.1 Setup", "&Finish")

You can download the .exe of the script from here

If you want to test what this script does, place both the exe of the script and pdfAppraiser.exe in the same path, and double click on the exe of the script and watch it runs within seconds.

Explanation of the code:

Run(...) - this method starts the installer
WinWaitActive(title, active button/etc.) - this method waits until the window that titled as title appears with an active button specified. 
Send(...) -Sends a command to proceed to the next window or else you want to do. 

You may wonder how I found these &Next > and other names of the buttons, I found these by using AutoIt Window Info tool, this tool will help you to see what are the names or commands or mnemonics used by the GUI developer.

Hope this post will give you some idea about AutoIt, and believe that you will use this tool.