AutoIT

From Omnia
Jump to navigation Jump to search

AutoIT

AutoIt - Wikipedia:

AutoIt (pronounced aw-tow-it) is a freeware automation language for Microsoft Windows. In its earliest release, the software was primarily intended to create automation scripts (sometimes called macros) for Microsoft Windows programs. Such scripts proved useful for "hands-free" completion of highly repetitive tasks, such as rolling out a large number of PCs with identical installation instructions. With later releases, AutoIt grew to include enhancements in both programming language design and overall functionality.
With the release of AutoIt version 3, the syntax of the programming language was restructured to be more like the BASIC family of languages. A script can be compiled into a compressed, stand-alone executable which can then be run on computers that do not have the AutoIt interpreter installed.
A wide range of function libraries (known as UDF's, or "User Defined Functions") are included as standard or available from the website to add specialized functionality.

Version

AutoIt v3.3.6.1 released (16th April, 2010)

Documentation

AutoIt Online Documentation - http://www.autoitscript.com/autoit3/docs/

Tools

AutoIt Full Installation. Includes x86 and x64 components, and:

  • AutoIt program files, documentation and examples.
  • Aut2Exe - Script to executable converter. Convert your scripts into standalone .exe files!
  • AutoItX - DLL/COM control. Add AutoIt features to your favorite programming and scripting languages!
  • Editor - A cut down version of the SciTE script editor package to get started. Download the package below for the full version!

AutoIt Script Editor

"Customised version of SciTE with lots of additional coding tools for AutoIt"

Features:

  • Syntax Highlighting (syntax color coding)
  • Syntax Folding
  • suggest keywords or functions (auto complete?)

Download

AutoIt v3 - Downloads - http://www.autoitscript.com/autoit3/downloads.shtml

Code

hello world

MsgBox(0, "My First Script!", "Hello World!")
Run("notepad.exe")
WinWaitActive("Untitled - Notepad")
Send("This is some text.")

Console Text

ConsoleWrite("Hello World" & @CRLF)

includes

#include <file.au3>

variables

dim $A
$A = 1
If $A = 1 Then
    Send("...")
EndIf

strings

Escape double quotes with two quotes:

 "hello ""hi"" bye"

Append string:

$var = "hello" & "world"

keystrokes

Send("text{del}{tab}" & @CRLF)
Send("!n")  ; alt-n
Send("!{F4}")  ; alt-F4
Send("{DOWN}")
Send("{ENTER}")
Send("{SPACE}")

comments

; comments
send("...") ; comments
#cs --------
 ....
#ce

exit

exit
exit [return code]

keywords: Error code return code

functions

Func MyFunc($myvar, ByRef $myref)
  ...
EndFunc

code folding

#region - GUI Create
...
#endregion

dos command

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

execute programs

Run("notepad.exe")
RunWait("msiexec myfile.msi")
RunWait(@COMSPEC & " /c Start myfile.msi")
ShellExecuteWait("myfile.msi")

command line parameters

$CmdLine[0] is number of parameters
$CmdLine[1] is param 1 (after the script name)
$CmdLine[2] is param 2 etc
$CmdLineRaw that contains the entire command line unsplit

message box

MsgBox ( flag, "title", "text" [, timeout [, hwnd]] )
MsgBox(0, "title", "text")

http://www.autoitscript.com/autoit3/docs/functions/MsgBox.htm

wrap commands

Long commands can be wrapped with the "_" character

MsgBox(4096,"", "This is a rather long line, so I " & _
  "broke it with the underscore, _, character.")

window control

Wait for window (maybe not active):

WinWait("Untitled")
WinWait("Title", "", 5)   ; with timeout
; return 0 if window timeout

Wait for window to activate:

WinWaitActive("Untitled - Notepad")
WinWaitActive("Notepad", "Do you want to save")
WinWaitActive("WinZip Setup", "&Express setup (recommended)")  ; with 'E' as the alt option

Activate window:

WinActive("Untitled - Notepad")
; return 0 if window not found or activated

Close window:

WinClose("Untitled - Notepad")

Get title of active window:

WinGetTitle("[active]")

sleep

sleep 5 seconds:

sleep(5000)

mouse click

MouseClick ( "button" [, x, y [, clicks [, speed ]]] )
; Double click at 0,500
MouseClick("left", 0, 500, 2)
  • button The button to click: "left", "right", "middle", "main", "menu", "primary", "secondary".
  • x, y [optional] The x/y coordinates to move the mouse to. If no x and y coords are given, the current position is used (default).
  • clicks [optional] The number of times to click the mouse. Default is 1.
  • speed [optional] the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.

NOTE: Find the mouse coordinates using the included AutoIT Window Info application

mouse move

MouseMove ( x, y [, speed = 10] )
  • speed [optional] the speed to move the mouse in the range 1 (fastest) to 100 (slowest). A speed of 0 will move the mouse instantly. Default speed is 10.

loops

Language Reference - Loops Statements - https://www.autoitscript.com/autoit3/docs/intro/lang_loops.htm

While 1
  ...
WEnd
$i = 1
While $i <= 10
  ...
  $i = $i + 1
WEnd

Examples

Keyboard Automation #1

WinActivate("half screen - 216.119.199.20 - Remote Desktop")

$i = 1

for $i = 1 to 86

#send("!d")
send("!u")
send("{down}")
send("{up}")
sleep(100)

next

Starwind Automation

Dim $lun

;$lun=43

for $lun = 120 to 120


WinActivate("StarWind Management Console")
;WinActivate("Add Target Wizard")

Send("!t")
Send("{Enter}")

Send("lun" & $lun )
sleep(1000)
Send("!n")

sleep(1000)
Send("!n")

MouseClick("left", 505, 395)
sleep(1000)
Send("!n")

MouseClick("left", 505, 418)
sleep(1000)
Send("!n")

Send("sw2")
Send("{tab}")
Send("{tab}")
Send("{tab}")
Send("root")
Send("{tab}")
Send("starwind")
sleep(1000)
Send("!n")

sleep(1000)
Send("!n")

Send("My Computer\D\images\lun" & $lun & ".img")
Send("{tab}")
Send("{tab}")
Send("My Computer\D\images\lun" & $lun & ".img")
Send("{tab}")
sleep(1000)
Send("!n")

sleep(1000)
Send("{enter}")

sleep(1000)
Send("{enter}")

Send("{tab}")
Send("10.20.30.1")
Send("{tab}")
Send("{tab}")
Send("{tab}")
Send("{tab}")
Send("{tab}")
Send("10.20.30.2")
Send("{tab}")
sleep(1000)
Send("!n")

Send("{down}")
Send("{down}")
Send("{down}")
sleep(1000)
Send("!n")

sleep(1000)
Send("!n")

sleep(1000)
Send("!n")

sleep(1000)
Send("{enter}")

;Sleep(20000)
WinWaitClose("Add Target Wizard")
Sleep(1000)

Next  ; next lun

Random Yes

WinActivate("Untitled - Notepad")

$i = 1

for $i = 1 to 20

   $choice = random(0, 100)
   if $choice < 80 Then
     send("y")
   EndIf
   send("{Enter}")

Next


Recording

AutoIt Recorder | Automation Developers
http://www.automationdevelopers.com/2016/09/autoit-recorder.html

Get from:

https://www.autoitscript.com/autoit3/files/archive/autoit/autoit-v3.3.14.0.zip

Au3Record in the Extras folder.

Or from here:

https://www.autoitscript.com/autoit3/files/archive/autoit/

ref: [1]


keywords