Using AutoIt to automate Windows tasks
I have used VBscript for several years to automate certain tasks. Some people are VERY leery of using VBscript, due to all the bad press about viruses written using VBscript.
The reason I switched to AutoIT is because it is so flexible. For example, you can automate mouse movements, which I never did successfully with VBscript. You can create your own windows, and interact with them fairly easily.
The best way to learn how to use AutoIT is to go through the example scripts that come with it. The help file is very well written, and has additional examples.
The first three examples below are based on my usage of AutoIt when I run my weekly backups. First, I need to give you some background, so the examples will make sense. Or you can check out this page, which has some screen shots and explanation from back when I used removable hard drives.
I use 250 gigabyte external USB hard drives for backup purposes. I back up four different computers to the same drive. One tedious task is setting up the 20 partitions on the drive. I have used the Disk Management tool in Windows XP to do this. To use this, follow these steps: Start Menu / Control Panel / Administrative Tools / Computer Management / Disk Management. If I later need to resize the partitions, I use Partition Magic.
In the past, I actually mapped drive letters on each computer for the partitions that I used on the backup drive. This did not work very well, since I use two backup drives - one at the office, and one in a safety deposit box. The problem was that Windows XP got confused when I swapped the drives. Unlike Windows 98, the Windows XP / 2000 "remembers" which hardware matches up to the drive letters.
The solution is to temporarily map the drive letters before I run my backups. In order to do this, you have to create a network share. This requires that you perform several steps:
1. Create an empty NTFS folder
AutoIt script examples
1. Mount a drive in an NTFS folder
1. Mount a drive in an NTFS folder
The script loads the Disk Management applet, then waits for you to select the partition to mount. When you press OK, it performs the steps to mount the drive.
The only thing you need to change in the script is the number of down-arrows to send (near the end). I have drives C through K, and I use drive H as my empty NTFS folder for the mount points. I have to skip down five drives from C to get to the H drive.
After I create the mount point for the drive, I still can't map a drive letter using a .cmd file. The network share from the prior step has to be set up as sharable first.
This script opens the Disk Management applet. Then it creates a window with a text box. You need to click on the empty NTFS folder that you used to set up the network share in the prior step. Then you should click on the share, and drag it into the text box.
The script uses that window to read the share name. This is used later in the script to identify certain windows that appear, since they also have the share name in the window caption.
When you click on the OK button, the script then uses Shift-F10 to open the context window for the network share. It is set as sharable, and then the permissions are set. Since I am paranoid, I only allow members of the administrators group to have read / write access to the files.
The last thing the script does is to prompt you to turn off indexing on the files that correspond to the network share. This will make it easier to remove the USB drive after the backups are created. If the indexing service is running on the drive, it won't let you remove the drive.
There is one thing that you may need to change inside of Windows, otherwise this
script may not work for you. The script assumes you are NOT using "simple sharing".
This is an option that you can turn on or off from Windows Explorer.
Click on the Tools menu / Folder Options / View tab, and then scroll down to the last item in
the list. Un-check the box for "Use simple file sharing (Recommended)."
Sometimes you may need to delete a LOT of drive letters. When I hook up a USB drive with 20 partitions to a computer for the first time, it will try to assign a drive letter to each partition (until it runs out of drive letters).
This script opens the Disk Management applet. Then it prompts you to
select the drive, and then click the OK button so the script can continue.
It deletes the drive letter assigned for the current drive, then moves down to the
This is a program that is no longer available, but it
is a good example of using AutoIT. When a spam gets through to my inbox, I
must send it back to myself, and train SAProxyPro to learn that it is
After I click on OK, I click on the SAProxyPro window to make it the active window.
At that point, the script takes over, and clicks various buttons and windows to
allow SAProxyPro to read the email message from my Outlook Express inbox, and
recognize it as spam.
At the end of the script, it also exits from SAProxyPro.
Last modified: November 28, 2011