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. How can I run a DOS program from within AutoIt?
  2. Why can I only use Run() to execute .exe and .com files? What about .msi / .txt and others?
  3. Why do I get errors when I try and use double quotes (") ?
  4. What do the window "title" and "text" parameters mean?
  5. Why can't I print a variable using "My var is $vVariable"?
  6. When I use Send() to send a variable odd things happen?
  7. What is the difference between the return value and @error?
  8. How can I exit my script with a hot-key?
  9. How can I use a custom icon when compiling my scripts?
  10. How can I make sure only one copy of my script is run?
  11. What are the current technical limits of AutoIt v3?
  12. I get a missing picture symbol in the Help file under the Examples.

1. 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


2. 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 "my_installer.msi" file what actually happens in the background is that "msiexec.exe my_installer.msi" is executed. So to run a .msi file from AutoIt you would do:

RunWait("msiexec my_installer.msi")

 

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

RunWait(@ComSpec & " /c Start my_installer.msi")

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

ShellExecuteWait("my_installer.msi")

Back To Top


3. 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:

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

or use single quotes instead:

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

 

Back To Top


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

There is a detailed description here.

 

Back To Top


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

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

#include <MsgBoxConstants.au3>

MsgBox($MB_OK, "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:

#include <MsgBoxConstants.au3>

MsgBox($MB_OK, "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 $vVar1 to $vVar5 into a string then it may be easier to do:

#include <MsgBoxConstants.au3>

Local $sMessage = StringFormat("Var1 is %s, Var2 is %s, Var3 is %s, Var4 is %s", $vVar1, $vVar2, $vVar3, $vVar4)
MsgBox($MB_SYSTEMMODAL, "", $sMessage)

 

Back To Top


6. 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($vMyVar, 1)

 

Back To Top


7. 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


8. 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   ;==>MyExit

 

Back To Top


9. 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


10. 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


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

Please refer to the Limits and Defaults section for the technical limits of AutoIt3.

Additional information about theoretical limits of AutoIt3.

Value Description
No limit Maximum number of GUI windows.
No limit Maximum number of use defined functions.
No limit Maximum number of variables in use at one time.
1.7E308 to 1.7E+308 Number range (floating point) with 15-digit precision.
0x8000000000000000 to 0x7FFFFFFFFFFFFFFF Hexadecimal number range (32-bit/64-bit signed integer).

 

Back To Top


12. 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