AutoIt online help

 
AutoIt

Frequently Asked Questions (FAQ)

This section gives some of the more frequently asked questions from the forum.  If you can't find the answer you seek here then the forum should be your first port of call.

Questions

1. Why doesn't my old AutoIt v2.64 script run in v3?

2. Isn't v3 much more difficult than previous versions?

3. How can I convert my v2.64 scripts to v3?

4. Where is the "goto" command?

5. How can I run a DOS program from within AutoIt?

6. Why can I only use Run() to execute .exe and .com files?  What about .msi / .txt and others?

7. Why do I get errors when I try and use double quotes (") ?

8. What do the window "title" and "text" parameters mean?

9. Why can't I print a variable using "My var is $variable"?

10. When I use Send() to send a variable odd things happen?

11. What is the difference between the return value and @error?

12. How can I exit my script with a hot-key?

13. How can I use a custom icon when compiling my scripts?

14. How can I make sure only one copy of my script is run?

15. What are the current technical limits of AutoIt v3?

16. I get a missing picture symbol in the Help file under the Examples.

 

 

1. Why doesn't my old AutoIt v2.64 script run in v3?

v3 has a different language structure to v2.64.

Previous versions of AutoIt were fine for what they were designed for - writing simple scripts to help with software installations.  Over time people began using it for general and complicated scripting tasks.  The old syntax and structure made this possible but very very difficult and cumbersome.  The decision was made to make AutoIt more suitable for general automation tasks and to achieve that a more standard and basic-like language was made.  This also means that if you already know a scripting language you will pick AutoIt v3 up easily.

 

Back To Top

2. Isn't v3 much more difficult than previous versions?

No.  In fact in many instances it's much easier than previous versions as you don't have to try and force the language to do something it was never designed to do.  It also uses a familiar BASIC-like language, and BASIC is known for being...well...basic :)

 

The vast majority of old AutoIt scripts were focused around software installation and clicking "Next" a lot in dialog boxes.  Most of these scripts can be converted to v3 simply by adding a couple of brackets here and there.  Here is an example of such a script in v2 and v3 (simulating a software installation with a few dialogs that have a Next button and a Finish button)

 

; v2.64 Script
WinWaitActive, Welcome, Welcome to the XSoft installation
Send, !n
WinWaitActive, Choose Destination, Please choose the
Send, !n
WinWaitActive, Ready to install, Click Next to install
Send, !n
WinWaitActive, Installation Complete, Click Finish to exit
Send, !f
WinWaitClose, Installation Complete

; v3 Script
WinWaitActive("Welcome", "Welcome to the XSoft installation")
Send("!n")
WinWaitActive("Choose Destination", "Please choose the")
Send("!n")
WinWaitActive("Ready to install", "Click Next to install")
Send("!n")
WinWaitActive("Installation Complete", "Click Finish to exit")
Send("!f")
WinWaitClose("Installation Complete")

 

Now, that wasn't so bad! :)  As all "strings" are enclosed in quotes you no longer have to wrestle with problems caused by leading and trailing spaces in text.  There is also fantastic support for many text editors so that when you are writing v3 scripts you can have syntax highlighting which makes everything much easier.

 

Back To Top

3. How can I convert my v2.64 scripts to v3?

The first thing you should ask yourself is "Do I need to convert my script?".  v2.64 will continue to be downloadable and supported so don't update all your scripts just for the sake of it - well not unless you want to :)

 

There is a section in the Help file that shows how the commands in v2 and v3 are related - click here to see the page.

 

One of the AutoIt v3 authors has written a utility to automatically convert v2 scripts to v3.  Conversion is pretty good unless your code is a rats-nest of gotos :)  You can find the converter in the "Extras" directory (Start \ AutoIt v3 \ Extras - or look in the directory that you installed AutoIt v3).

 

Back To Top

4. Where is the "goto" command?

Gone.  It's evil.  No, you can't ask why - it just is.  It's like that lump of rock they find in the microwave at the end of the film Time Bandits :)

 

AutoIt v3 features most of the common "loops" in use today and with these Goto is no longer required.  Look up While, Do, For, ExitLoop, ContinueLoop and Functions for the modern way of doing things :)  And while you are looking at help file sections check out these on loops, conditional statements and functions.  I promise you, once you have got the hang of such things you will be able to script in virtually any other language within a couple of minutes.

 

Just to get you started, the most basic use of Goto in version 2.64 was an infinite loop like:

:mylabel
...do something...
...and something else...
goto, mylabel

A simple v3 version of that is a While loop that is always "true".

While 1 = 1
   ...do something...
   ...do something else...
Wend

 

Back To Top

5. How can I run a DOS program from within AutoIt?

If you wanted to run something like a DOS "Dir" command then you must run it though the command interpreter (command.com or cmd.exe depending on your OS).  The @Comspec macro contains the correct location of this file.  You should use the RunWait() function as it waits for the DOS program to finish before continuing with the next line of the script.  Here is an example of running the DOS Dir command on the C: drive: (effectively running the command command.com /c Dir C:\ )

    RunWait(@COMSPEC & " /c Dir C:\")

 

Back To Top

6. Why can I only use Run() to execute .exe files?  What about .msi / .txt and others?

Only a few file extensions are usually "runable" - these are .exe, .bat, .com, .pif.  Other file types like .txt and .msi are actually executed with another program.  When you double click on a "myfile.msi" file what actually happens in the background is that "msiexec.exe myfile.msi" is executed.  So to run a .msi file from AutoIt you would do:

    RunWait("msiexec myfile.msi")

 

Or, run the command "start" which will automatically work out how to execute the file for you:

    RunWait(@COMSPEC & " /c Start myfile.msi")

 

Or, use the ShellExecuteWait function which will automatically work out how to execute the file for you:

    ShellExecuteWait("myfile.msi")

 

Back To Top

7. Why do I get errors when I try and use double quotes (") ?

If you want to use double-quotes inside a string then you must "double them up".  So for every one quote you want you should use two.  For example if you wanted to set a variable to the string: A word in "this" sentence has quotes around it!  You would do:

    $var = "A word in ""this"" sentence has quotes around it!"

or use single quotes instead:

    $var = 'A word in "this" sentence has quotes around it!'

 

Back To Top

8. What do the window "title" and "text" parameters mean?

There is a detailed description here.

 

Back To Top

9. Why can't I print a variable using "My var is $variable"?

If you have a variable called $msg and you want to print in inside a MsgBox then this will NOT work:

    MsgBox(0, "Example", "My variable is $msg")

It will actually print  My variable is $msg . What you need to do is tell AutoIt to join the string and the variable together using the & operator:

    MsgBox(0, "Example", "My variable is " & $msg)

 

Advanced: If you have many variables to add into a string then you may find the StringFormat() function useful.  For example, if I wanted to insert $var1 to $var5 into a string then it may be easier to do:

     $msg = StringFormat("Var1 is %s, Var2 is %s, Var3 is %s, Var4 is %s, Var5 is %s", $var1, $var2, $var3, $var4, $var5)
     MsgBox(0, "Example", $msg)

 

Back To Top

10. When I use Send() to send a variable odd things happen?

If you are sending the contents of a variable then be mindful that if it contains special send characters like ! ^ + {SPACE} then these will be translated into special keystrokes - rarely what is wanted.  To overcome this use the RAW mode of Send() that does not translate special keys:

    Send($myvar, 1)

 

Back To Top

11. What is the difference between the return value and @error?

Generally a return value is used to indicate the success of a function.  But, if a function is already returning something ( like WinGetText() ) then we need to have a way of working out if the function was successful, so we set @error instead.

 

Back To Top

12. How can I exit my script with a hot-key?

Ah, an easy one.  If you want to make your script exit when you press a certain key combination then use the HotKeySet() function to make a user function run when the desired key is pressed.  This user function should just contain the Exit keyword.

Here some code that will cause the script to exit when CTRL+ALT+x is pressed:

HotKeySet("^!x", "MyExit")
...
...
; Rest of Script
...
...
Func MyExit()
    Exit
EndFunc

 

Back To Top

13. How can I use a custom icon when compiling my scripts?

You need to run the full compiler program (rather than just right-clicking a script and selecting compile).  This page describes the compiler in detail.

 

Back To Top

14. How can I make sure only one copy of my script is run?

Use the _Singleton() function. See the User Defined Functions documentation for more information on _Singleton() and how to use it.

Back To Top

15. What are the current technical limits of AutoIt v3?

Here are details of the current technical limits of AutoIt. Please note that some of the limits are theoretical and you may run into performance or memory related problems before you reach the actual limit.

 

Maximum length of a single script line: 4,095
Maximum string length: 2,147,483,647 characters

Number range (floating point): 1.7E–308 to 1.7E+308 with 15-digit precision
Number range (integers): 64-bit signed integer
Hexadecimal numbers: 32-bit signed integer (0x80000000 to 0x7FFFFFFF)

Arrays: A maximum of 64 dimensions and/or a total of 16 million elements
Maximum depth of recursive function calls: 5100 levels

Maximum number of variables in use at one time: No limit
Maximum number of user defined functions: No limit

Maximum number of GUI windows: No limit
Maximum number of GUI controls: 65532

 

Back To Top

16. I get a missing picture symbol in the Help file under the Examples.

This should be the Open button that enable you to open the Examples in the Help file.
This issue is that the hhctrl.ocx isn't properly registered or corrupted.
Try registering it by doing "regsvr32 hhctrl.ocx" from the command prompt or check if the file is still valid.
 

Back To Top

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

AUTOIT http://autoitscript.com
Online Service http://lampiweb.com