What is AutoIt Scripting Language?

Ξ June 8th, 2008 | → | ∇ AutoIT |

AutoIt Scripting Language is a very user-friendly programming language. I use AutoIt quite frequently because it allows you to automate repetitive, monotonous tasks saving you valuable time and energy. I personally feel that if you have to do something that takes you 10 minutes 5 times a week, then you should spend the time (even if it takes 2 days) to automate that task so that you are then free to do other things. It helps to have some programming experience when you start using AutoIt, but I don’t think it’s really a requirement. AutoIt is a very simple, English like language, and it has an excellent help file. AutoIt allows you to easily read and write data from file, ini files, and the registry. Another great feature of AutoIt is that you can control the keyboard and mouse, which means you can automate just about any task you can do manually with the keyboard and mouse. The best feature of AutoIt is that you can compile your AutoIt scripts into executable files so you can run your script on any Windows machine without having to install the AutoIt software. There is a special text editor available through the AutoIt website, called SciTE, which has many AutoIt related functions built-in. My favorite feature of SciTE is the type-ahead feature that lets you type in a few characters of a command or variable and then displays a list of possible choices you can select. This is an amazing time saving feature that is often found in high-end commercial programming environments. SciTE has built-in functions to “tidy up” your code, compile your script, build a GUI interface, and much more. AutoIt was originally intended to supplement other scripting languages, but it my opinion, it has surpassed them.

So, now hopefully you think AutoIt is pretty cool. What next? Download AutoIt from www.autoitscript.com, you can get SciTE from http://www.autoitscript.com/autoit3/scite/, so now you can start playing around with it. I highly recommend that you read the help file FIRST and follow their tutorials, creating your own scripts, so you can get used to it (hopefully using the SciTE editor). OK, so you did that, now what? Probably the next best thing to get an understanding of is data types and variables. Read the sections of the help file about data types and variables, but make sure you take note of variable Scope and Arrays, especially if you don’t have much programming background. I would also recommend that you glance over the Operators and Macros section of the help file, but no need to memorize the Macros because SciTE has that lovely type-ahead feature. The main thing left to do is figure out what you want to automate! Figuring out how to logically automate your processes is the most difficult part of creating an AutoIt script. When trying to automate the installation of WinZip, you have to make sure that you can handle any anomalies that may occur. I’m not sure if the tutorial provided even still works with newer versions of WinZip, but let’s assume it does. What would happen with your script if during the installation process, WinZip gave a pop-up message saying that you were out of space on the C: drive? Your program would error out waiting for the next window to appear. That example doesn’t seem to serious, so let’s do another example; let’s says you write a script to read in a list of names and phone numbers from a text file and type them in to Outlook or something. Your program is setup to read in the numbers formatted only with a “-“. What will happen if some goober out there gives you a phone number like this… (123) 456-7890? How will your program handle that? Will it skip it completely, will it only put in 456-7890, will it cause your whole program to fail, or will it work properly? When you write your programs you have to think of each individual step of the program and be sure that one little anomaly will not cause ill effects to your end goal. When I write programs, I like to try to handle a few possible error scenarios, and then have a catch all that will tell me details of the error that occurred. Wouldn’t it be nice if when your WinZip script came across that “no disk space” error, it automatically generated a list of windows that were open when the error occurred? It can often be difficult to reproduce the exact error conditions that you run into when a script runs across 100 workstations or 100 servers, so having good troubleshooting information (error logs) is essential to debugging your script.

And now, the easiest and most important part of AutoIt…Functions! AutoIt functions are built-in commands that allow you to do all the cool things that I’ve mentioned before. Want to read a value from the registry? Call the RegRead function, tell it the registry key and value you want, and it will store it in a variable for you. Want to see that registry value? Call the MsgBox function to display the variable. Want to write that value out to a log? Call the FileWrite function. Need to read a value from an .ini file, but don’t know what the function is? In SciTE, type Ini, and you’ll see a list of functions that start with Ini (IniRead, IniWrite, IniDelete, etc). And what if you’re not really sure what you want or need to do? Browse through the well organized help file and you’ll see all the categories of functions, and you’ll easily be able to find what you’re looking for. Now, you want to know the really cool part…you can create your own functions! Let’s say that you took my advice and write your programs with really good error logging, did you notice how you have to call the FileOpen, FileWriteLine, and FileClose functions several times? All you have to do is create your own function that will do it for you, so you can save yourself from all that typing. Just create a function that will take a message and a file names as parameters, then in the function, make your FileOpen & FileClose commands open & close the specified file, and have your FileWriteLine write out the specified message. That’s how simple it is!
I’m going to be doing more posts about AutoIt, since I just love it so much, but I did want to include some scripts that I have written in the past that have been pretty useful (& fun) for me:

All Samples

Logon-AuthorizedUser.au3
Description: This Script checks the @UserName macro to make sure it’s the username that you specified and if it’s not, it will display a popup message saying that you are not authorized to login to this computer, and then reboot! It’s a very nice thing if you don’t like sharing your computer with other people, but be careful using it at work because I’m sure your boss won’t like being told he’s not authorized to use your computer.
How to use it: Edit the script and change the username to your Windows user name. I like to compile all of my scripts, but it’s not necessary. Copy the script (or executable) to your “All Users” Startup folder - “c:\Documents and Settings\All Users\Start Menu\Programs\Startup\”. Now if anyone else logs in to your box, it will reboot in 15 seconds!


MapDrives.au3
Description: This script will map a network share to the drive letter you specify.
How to use it: Edit the script and put in your drive mapping information, then just run the script (or executable) and it will map the drives for you! This works great as a domain login script (you may need to add error logging though)

ProxySwitcher.au3
ProxyConfig.ini
Description: If you have multiple proxy servers that you use, this program will display a GUI with a drop down list of proxy servers, simple select the proxy server you want to use and it will automatically change it for you in Internet Explorer. The only bad thing is that if you have Internet Explorer open, you have to restart it for the change to take affect because the script just modifies the registry values.
How to use it: Edit the .ini file that is included with it and type in your proxy information in the format specified. Then just run the script (or executable) and select your proxy.

Remember to tune in for future AutoIt related posts!

 

Leave a reply


About

    Place for about text

    The Detox theme is built with PS, brushes and patterns by milo IIIIVII.

    Open right sidebar.php in the theme folder to edit this message.
    Check my other themes too.

     

FlickR

    Solitude
    Solitude
    Solitude
    Solitude