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.
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:\")
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")
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!'
There is a detailed description here.
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)
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)
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.
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
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.
Use the _Singleton() function. See the User Defined Functions documentation for more information on _Singleton() and how to use it.
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). |
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.