Do you have a stubborn piece of software that only comes as an EXE and doesn’t support a silent install? AutoIT, a free application, can be a great tool for deploying these stubborn programs or allowing end users to install approved programs without having administrative rights. In this guide, we will cover automating installs with AutoIT.
You can download AutoIT from here. I recommend downloading and installing the Full Installation and the AutoIT Script Editor, the Full Installation only has a cut down version of the editor.
Once you have AutoIT installed, you can right click on your desktop or in any folder and choose New -> AutoIT v3 Script. Name the script, right click on it and choose “Edit Script”. Edit the Author and Script Function attributes so tthat you know who created the script and what it’s supposed to do. This can be very beneficial if you are sharing scripts with others.
For this demonstration we are going to be installing TuxMath. I recommend saving the executable to a network share that your users only have read access to and pointing the script there to install. If you run the script and the installer from the same directory, a user can gain administrative rights. This is done by renaming another exe file to the name of the installer you are trying to install. The read permissions are important.
Starting Our AutoIT Script
We want to check to see if the program is already installed and if so exit, but if not continue with the install. To accomplish this, we will use an If Then statement
So let’s check to see if the file is there. If it is, exit the program:
1 2 |
If FileExists(@ProgramFilesDir &”\TuxMath\TuxMath.exe”) Then Exit |
The editor has auto complete for functions and macros. The lines we have just entered says to look to see if c:\Program Files\TuxMath\TuxMath.exe or c:\Progam Files (x86)\TuxMath\TuxMath.exe exists and if it does then to exit. This makes working with X86 and X64 operating systems easier.
Next if the program is not already installed we want to tell it what to run and what user to run as
1 2 |
Else RunAs(“adminuser”, “domain.local”, “adminpass”, 0, “\\domain.local\software\files\TuxMath\tuxmath-2.0.2-win32-installer.exe” |
Completely Automating an Install with AutoIT
At this point we could just put an EndIf and allow the end user to finish the installation, but sometimes we have end users who are not sure what to click, or perhaps you want to run this as a logon or logoff script and not have to worry about the end user clicking through everything. Here is where things get fun with AutoIT.
Run the executable that you want to install, but don’t click any of the buttons yet. Go to the Tools menu of the script editor and choose AU3Info or just press Ctrl+F6 (If you don’t see AU3Info you didn’t install the full version of the editor).
In the AU3Info tool, you will see a “Finder Tool”. Click and drag that tool over the first button you want to click. This will allow you to find all the information you need about that button and the window to tell AutoIT that is the button you want to click. You will want to take note of the Window Title, some of the text that should be unique to that window from the “Visible Text” tab, and the ID from the “Control” tab.
Now we will tell the script to wait for the window to open, bring the window to the front if it is not already and click the button. Here is how to do that:
1 2 3 |
WinWait(“Tux of Math Command Setup: License Agreement”, “GNU GENERAL PUBLIC LICENSE”) WinActivate(“Tux of Math Command Setup: License Agreement”, “GNU GENERAL PUBLIC LICENSE”) ControlClick((“Tux of Math Command Setup: License Agreement”, “GNU GENERAL PUBLIC LICENSE”, 1) |
When we look inside our parentheses, the first text we have is the window title, then we have some of the window text, this should be the same for all 3 commands, in the ControlClick command we add the ID of the button that we want to click.
Repeat the steps for any additional buttons that need to be clicked.
To end your script just use Endif to close out of your if statement.
I had a few computers that would pop up an “Open File – Security Warning” so added an additional if statement to my script as well as adding a sleep statement to make give time for the warning to pop up since I’m running from a network share. As an alternative, you can add the server’s UNC to your trusted sites list.
Here is my complete script:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.10.2 Author: Alan Script Function: Install TuxMath #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here if FileExists(@ProgramFilesDir & "\TuxMath\TuxMath.exe") Then Exit Else RunAs("adminuser","domain.local","password", 0, "\\domain.local\software\files\tux math\tuxmath-2.0.2-win32-installer.exe") sleep(15000) if WinExists("Open File - Security Warning", "We can’t verify who created this file.") Then WinWait("Open File - Security Warning", "We can’t verify who created this file.") WinActivate("Open File - Security Warning", "We can’t verify who created this file.") ControlClick("Open File - Security Warning", "We can’t verify who created this file.", 1) WinWait("Tux of Math Command Setup: License Agreement", "GNU GENERAL PUBLIC LICENSE") WinActivate("Tux of Math Command Setup: License Agreement", "GNU GENERAL PUBLIC LICENSE") ControlClick("Tux of Math Command Setup: License Agreement", "GNU GENERAL PUBLIC LICENSE", 1) WinWait("Tux of Math Command Setup: Installation Options", "Select components to install:") WinActivate("Tux of Math Command Setup: Installation Options", "Select components to install:") ControlClick("Tux of Math Command Setup: Installation Options", "Select components to install:", 1) WinWait("Tux of Math Command Setup: Installation Folder", "Choose a directory to install Tux of Math Command in to:") WinActivate("Tux of Math Command Setup: Installation Folder", "Choose a directory to install Tux of Math Command in to:") ControlClick("Tux of Math Command Setup: Installation Folder", "Choose a directory to install Tux of Math Command in to:", 1) Else WinWait("Tux of Math Command Setup: License Agreement", "GNU GENERAL PUBLIC LICENSE") WinActivate("Tux of Math Command Setup: License Agreement", "GNU GENERAL PUBLIC LICENSE") ControlClick("Tux of Math Command Setup: License Agreement", "GNU GENERAL PUBLIC LICENSE", 1) WinWait("Tux of Math Command Setup: Installation Options", "Select components to install:") WinActivate("Tux of Math Command Setup: Installation Options", "Select components to install:") ControlClick("Tux of Math Command Setup: Installation Options", "Select components to install:", 1) WinWait("Tux of Math Command Setup: Installation Folder", "Choose a directory to install Tux of Math Command in to:") WinActivate("Tux of Math Command Setup: Installation Folder", "Choose a directory to install Tux of Math Command in to:") ControlClick("Tux of Math Command Setup: Installation Folder", "Choose a directory to install Tux of Math Command in to:", 1) Endif EndIf |
Hi.
In my case, exe name changes daily. (A new build comes daily). Exe names is like 3.0.0.21023-win64.exe and in next day its 3.0.0.21024-win64.exe.
How can i avoid this hardcoding?
Off the top of my head, my first thought would be to create a batch file that is called on that renames the file.
Possibly something that works along these lines.
check if install.exe exists if yes goto checkForNewBuild else goto install
:checkForNewBuild
check if *.win64.exe exists if yes goto rename else goto install
:rename
rename *.win64.exe install.exe
:install
install.exe
exit
I haven’t used AutoIT much since I did the tutorial, but I believe you can incorporate this into the Script, but it not you can use a scheduled batch file that runs and renames the script.
My Installation stuck at the first screen. I followed your instruction but no avail. Any idea y this would happen?
Make sure your script is set to click any appropriate check boxes that it may need to be clicked before the installation can proceed. Can you post a copy of your script? Be sure you remove any sensative information from the script.
I have used AHK to automate a lot of things in the past, this is the first time I was going to look at automating installers and figure I would give AutoIT a shot.
Now I am not familiar with all the scripting language yet, but looking at this I see your calling directly to the controls for the installer rather than sending key presses.
With that said isn’t all the “winactivate” scripting totally redundant and not necessary, the window should not have to be in focus if you’re calling to it directly, even if you were sending key presses I would image a single activate command would keep the window in focus for the duration of the install process.
Any thoughts/opinions?
The installer does have to stay active for the installer to work, and an end user can click elsewhere to remove the focus from the installer. It should work with just the one activate command, but duplicating the command each time helps insure that it will not fail due to the end user.
Thought so, but I tried it out and actually I did have issues if clicking away. With AHK I never had an issue the window could be hidden or minimized no issues.
Still works pretty well, while not much faster with installing via this method vs just doing it by hand what it enables me to do is launch via another device and have it fully automated or chain together multiple installers into a single script.
Maybe I’m missing something, but doesn’t this have a huge security issue by exposing the username and password of a domain administrator for any user to read from the script file?
Thanks for pointing that out, I did miss an important step in the tutorial.
Once you have the script working the way you want, go to Options and choose Build, or just press F7, to build an EXE that you can run via startup or shutdown script.
Really good guide – I always thought autoIT would be hard but it doesn’t seem too difficult at all.