Automation with AutoIT Tutorial: Part 1

In our last “computer repair tool of the week” article we posted about the application called Universal Silent Switch Finder which has the ability to find hidden install switches. The advantage of knowing what these hidden switches are is that it allows you to control the way a piece of software is installed. For example, if we were to install something like Spybot and we used its “silent” switch, it would install Spybot without ever showing us an install screen or asking us any questions. The main advantage of this is that it allows us to automate what we do.
Lets say that you install a certain set of software on every system that you sell like Spybot, Ad-Aware and AVG antivirus. You can make this a 1 click process and let the application that you created do all the work. In this article, we’ll show you how to do it.

We will be making our automation application using a tool called AutoIT. AutoIT is a basic scripting language which is easy to learn but does require a little bit of coding knowledge.

Introduction to AutoIT

To begin, download AutoIT HERE and install it.

In a folder of your choice, create a new text document (right click in a open area, go to New > Text Document). You can name it whatever you want but change the extension to .au3 . This is the scripting file that AutoIT will be using and where we will be placing our code. You can open this file with any text editor but AutoIT also comes with a special editor that makes things a little easier.
If you right click on your new .au3 file, there will be three new options: Compile Script, Edit Script and Run Script. Choose Edit Script.

You should see the contents of an empty file that looks like a blank text file, this is where we will be placing our code.

To begin with a very basic script, enter the following line into your script file and click save.
RunWait("C:\WINDOWS\system32\defrag.exe C: -f")
Below that line, also add:
Exit

This command starts a defrag of the C: drive and the -f switch forces a defragmentation even if the free space is low. If you ran this command in DOS yourself, you would get the exact same outcome. You can also try this with many other DOS commands. As for the exit line, it just tells the script to close when its finished.

Now we know what it does, right click on your .au3 file and choose “Run Script”. You should see the DOS window show up and it will start defragging the C: drive.

The problem with .au3 files is that the “Run Script” option wont show up on other computers unless they have AutoIT installed so we need to compile the script to make it portable. Right click on your .au3 file again and choose “Compile Script”. This will create an .exe version of your script.

So if you have named your au3 script mycode.au3, there will now be a file called mycode.exe. This has made our script portable and can be run on any Windows computer.

Automating Installs

For this automated install example, we’ll be installing the popular compression software 7zip which you can download here.

Once it has been downloaded, we need to find out which “switch” tells the 7zip installer to install silently so that it doesn’t show us the setup menu. To do that, we can use Universal Silent Switch Finder which you can download here.

Run Universal Silent Switch Finder, press the > button and find the 7zip install. It will then fill out the “Usage” field which should be “7z457.exe” /S which means /S is our “silent switch”.

Clear out your old .au3 scripts or start a new one and add:
RunWait("7z457.exe /S ")
Exit

This script assumes that the 7zip installer is in the same directory as the script.
Note: Be careful with the quotation marks because the line from USSF and the line needed in the code have them in different places.

Run this script and if you did it correctly, it will appear that nothing has happened. Check your Start Menu or the Program Files folder and you should see at 7zip has been installed.

To add mutliple applications to be automatically installed you would do something like:

RunWait("7z457.exe /S ")
RunWait("AVG8.exe /s ")
Exit

Automating the Running of Applications

AutoIT doesnt just limit you to just automating the install of an application, you can also automate the running of them too.

For example, we can tell an application like Clamwin which a portable virus scanner, to scan the C drive for viruses and once they are found, delete them, using the following line
RunWait("ClamWin.exe --mode=scanner --path=c: --remove --close")

To find the command line switches for different applications, try the applications documentation or search for them on Google.

That’s it for part 1 and we have barely scratched the surface with what AutoIT is capable of, in part 2 of our AutoIT article we’ll show you how to automate an installation of an application that doesn’t have install switches and how to install registry tweaks. For additional help with what we have worked with here, AutoIT has some great documentation.

Special thanks to our forum member focuz, who sent in many of his AutoIT automation examples which much of this article is based off.

On to part 2 >>



Bryce Whitty

About the Author

Bryce Whitty
More articles by me...
Bryce is an Australian computer technician and the founder of Technibble. He started his computer repair business when he was 17 years old and is still running it 9 years later. He is an avid traveller and spends at least a month of the year in another country.

Comments (10)

  • Phil P says:

    AutoIT is the best tool when dealing with computers. I’ve worked miracles with that program automating what others said was impossible. This tool is HIGHLY recommended.

  • Dexter says:

    So how is this better than a batch file? Aside form the fact that it is a .exe?

  • focuz says:

    AutoIT isn’t any better then batch files when all your doing is simple installs. It has its advantages when your doing things that you want a gui, and you can automate mouse and keyboard movements to run programs that don’t have silent switches.

  • techpro says:

    Wicked tutorial Bryce…hopefully more to come on AUTOIT????

  • Kj says:

    focuz,

    quick question…

    I’ve got an .exe to which the “/s” silent switch doesn’t do its job. I’ve been told to use AutoIT, but can’t seem to find out how to use those “keyboard movements” to actually automate this .exe!!

    Any suggestions?

    Many Thanks!

  • b00b says:

    Kj,
    For debug keyboard automations you can use “AutoIT Window Info”. Just run you application and look controls by “AutoIT Window Info”. In script you run the application under keyboard simulation by Run(“7z457.exe “), wait and look for it by window title or handle and you can simulate the keyboard and mouse. In AutoIt help and forum you can find a lot of examples.

  • berk says:

    thanks very much all about this informations. ı learn more knowledge those ı want .

  • nizul says:

    can i’m know where can i get tutorial in internet.. i am beginner in autoit..

  • sweta says:

    Hi, can someone tell me how to set switch to active for autoit3 macro generator which by default is set to passive.

  • Septeriady says:

    thanx a lot … for ur share….!