Jump to content
Jon

Using the AutoIt PowerShell Cmdlets

Recommended Posts

This is a quick start guide to using the AutoIt PowerShell Cmdlets. The best bits of AutoIt directly from PowerShell :) 

The files you need are as follows (get them from the zip file or the Program Files folder after installation):

  • AutoItX.psd1
  • AutoItX3.PowerShell.dll
  • AutoItX3.Assembly.dll
  • AutoItX3.dll
  • AutoItX3_x64.dll

To use the Cmdlets open a PowerShell cmd prompt and enter:

Import-Module .\AutoItX.psd1

 

Now you can get a list of available AutoIt Cmdlets by doing Get-Command *AU3*:

PS> Get-Command *AU3*

Name                              Category  Module 
----                              --------  ------ 
Invoke-AU3MouseWheel              Cmdlet    AutoItX
Move-AU3Mouse                     Cmdlet    AutoItX
Invoke-AU3MouseClickDrag          Cmdlet    AutoItX
Get-AU3MouseCursor                Cmdlet    AutoItX
Invoke-AU3MouseUp                 Cmdlet    AutoItX
Assert-AU3WinActive               Cmdlet    AutoItX
Assert-AU3WinExists               Cmdlet    AutoItX
Assert-AU3IsAdmin                 Cmdlet    AutoItX
Invoke-AU3Shutdown                Cmdlet    AutoItX
Send-AU3ControlKey                Cmdlet    AutoItX
Invoke-AU3MouseDown               Cmdlet    AutoItX
Invoke-AU3MouseClick              Cmdlet    AutoItX
Invoke-AU3ControlTreeView         Cmdlet    AutoItX
Invoke-AU3ControlListView         Cmdlet    AutoItX
Invoke-AU3ControlCommand          Cmdlet    AutoItX
Invoke-AU3ControlClick            Cmdlet    AutoItX
Move-AU3Control                   Cmdlet    AutoItX
Set-AU3ControlText                Cmdlet    AutoItX
Show-AU3Control                   Cmdlet    AutoItX
Hide-AU3Control                   Cmdlet    AutoItX
Get-AU3ControlText                Cmdlet    AutoItX
Get-AU3ControlFocus               Cmdlet    AutoItX
Set-AU3ControlFocus               Cmdlet    AutoItX
Disable-AU3Control                Cmdlet    AutoItX
Enable-AU3Control                 Cmdlet    AutoItX
Get-AU3StatusbarText              Cmdlet    AutoItX
Invoke-AU3RunAsWait               Cmdlet    AutoItX
Invoke-AU3RunAs                   Cmdlet    AutoItX
Invoke-AU3RunWait                 Cmdlet    AutoItX
Invoke-AU3Run                     Cmdlet    AutoItX
Set-AU3Clip                       Cmdlet    AutoItX
Get-AU3Clip                       Cmdlet    AutoItX
Set-AU3WinTrans                   Cmdlet    AutoItX
Set-AU3WinTitle                   Cmdlet    AutoItX
Set-AU3WinState                   Cmdlet    AutoItX
Set-AU3WinOnTop                   Cmdlet    AutoItX
Move-AU3Win                       Cmdlet    AutoItX
Show-AU3WinMinimizeAllUndo        Cmdlet    AutoItX
Show-AU3WinMinimizeAll            Cmdlet    AutoItX
Get-AU3WinState                   Cmdlet    AutoItX
Get-AU3WinProcess                 Cmdlet    AutoItX
Get-AU3WinClassList               Cmdlet    AutoItX
Get-AU3WinCaretPos                Cmdlet    AutoItX
Get-AU3WinClientSize              Cmdlet    AutoItX
Get-AU3ControlPos                 Cmdlet    AutoItX
Get-AU3ControlHandle              Cmdlet    AutoItX
Get-AU3MousePos                   Cmdlet    AutoItX
Get-AU3WinPos                     Cmdlet    AutoItX
Get-AU3WinHandle                  Cmdlet    AutoItX
Get-AU3ErrorCode                  Cmdlet    AutoItX
Initialize-AU3                    Cmdlet    AutoItX
Show-AU3WinActivate               Cmdlet    AutoItX
Close-AU3Win                      Cmdlet    AutoItX
Wait-AU3WinClose                  Cmdlet    AutoItX
Wait-AU3WinNotActive              Cmdlet    AutoItX
Set-AU3Option                     Cmdlet    AutoItX
Send-AU3Key                       Cmdlet    AutoItX
Wait-AU3Win                       Cmdlet    AutoItX
Wait-AU3WinActive                 Cmdlet    AutoItX
Get-AU3WinTitle                   Cmdlet    AutoItX
Get-AU3WinText                    Cmdlet    AutoItX

 

I’ll show how to use the Cmdlets using a simple example that will open notepad.exe and modify the edit window by setting the text and simulating some keystrokes. First create a blank PowerShell script called notepad_example.ps1 in the same folder as the AutoItX components above and open it for editing.

Now we want to import the PowerShell module which is AutoItX.psd1. Enter the following in the script:

Import-Module .\AutoItX.psd1

 

We want to run notepad.exe:

Invoke-AU3Run -Program notepad.exe

 

After notepad opens we want to wait for the notepad “Untitled -Notepad” window to appear. You might need to change the title for non-English versions of Windows:

$notepadTitle = "Untitled - Notepad"
Wait-AU3Win -Title $notepadTitle
$winHandle = Get-AU3WinHandle -Title $notepadTitle

 

Get-AU3WinHandle returns a native Win32 handle to the notepad window. We can use this handle in many other AutoIt functions and it uniquely identifies the window which is much more reliable than constantly using a windows title. If you have obtained a window handle using any other Win32 function you can use it with AutoIt.

After obtaining the handle to the notepad window we want to ensure that the window is active and then get a handle to the Edit Control. Using the AU3Info.exe tool that comes with AutoIt we can find that the name of the edit control in notepad is Edit1.

Show-AU3WinActivate -WinHandle $winHandle
$controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control "Edit1"

 

Now that we have a handle to the edit control we can set text in two ways: Directly (Set-AU3Controltext) or with simulated keystrokes (Send-AU3ControlKey):

Set-AU3ControlText -ControlHandle $controlHandle -NewText "Hello! This is being controlled by AutoIt and PowerShell!" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 1" -WinHandle $winHandle

Now let’s see what the entire script looks like:

# Import the AutoIt PowerShell module
Import-Module .\AutoItX.psd1

# Run notepad.exe
Invoke-AU3Run -Program notepad.exe

# Wait for an untitled notepad window and get the handle
$notepadTitle = "Untitled - Notepad"
Wait-AU3Win -Title $notepadTitle
$winHandle = Get-AU3WinHandle -Title $notepadTitle

# Activate the window
Show-AU3WinActivate -WinHandle $winHandle

# Get the handle of the notepad text control for reliable operations
$controlHandle = Get-AU3ControlHandle -WinHandle $winhandle -Control "Edit1"

# Change the edit control
Set-AU3ControlText -ControlHandle $controlHandle -NewText "Hello! This is being controlled by AutoIt and PowerShell!" -WinHandle $winHandle

# Send some keystrokes to the edit control
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 1" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}simulate key strokes - line 2" -WinHandle $winHandle
Send-AU3ControlKey -ControlHandle $controlHandle -Key "{ENTER}{ENTER}" -WinHandle $winHandle

 

This is how the notepad window should look if everything is working correctly:

notepad_powershell.thumb.png.a1896874f05

Share this post


Link to post
Share on other sites

Please add this to AutoItX HelpFile.

 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskScheduler

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2019-10-01

Share this post


Link to post
Share on other sites

Could we have examples for each commandlets in autoitx.

Example : get-help autoit-commandlet -full 

If that provides examples it would really help to incorporate faster.could not find any other resources in internet also. 

Edited by PrakashVel
Needed to complete the message info.

Share this post


Link to post
Share on other sites
On 11/29/2015 at 11:58 AM, PrakashVel said:

Could we have examples for each commandlets in autoitx.

Example : get-help autoit-commandlet -full 

If that provides examples it would really help to incorporate faster.could not find any other resources in internet also. 

Agreed.  The environment in which I work pretty much classifies any AutoIT script I write as a virus and quarantines it immediately, forcing me to use powershell.  Initially I thought I was just stupid (and/or lazy for disregarding the trial/error approach) for having difficulty in determining the autoit function that each powershell function was related to :P, but seeing as I am not the first to request that information be included with the module, I feel less stupid.  Please do include at least the autoit function that corresponds to the given powershell function in the autoit powershell module.  That would be greeeaaaattttt.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Similar Content

    • By Exit
      For my next project I would like to send files with "alternate data streams" by email in ZIP format.
      I can not use any external program like 7-Zip or WinRAR. (They would fit😥)
      Who knows how to create a ZIP file with "alternate data streams" included with the Powershell command "Compress-Archive"? 
      Here a test script:  (save as "ADSTester.cmd")
      @rem Try to create a zip file with alternate data streams (ADS) included @rem Housekeeping @cls @del ADSTester.zip >nul: @RD /S /Q Extracted >nul: @del ADSTester.txt >nul: @rem End of Housekeeping echo This is the ADSTester.txt file >ADSTester.txt echo This is the ADSTester.txt:Part1 file >ADSTester.txt:Part1 echo This is the ADSTester.txt:Part2 file >ADSTester.txt:Part2 dir /r ADSTester.txt @rem See the 3 files @rem **************************************************************** @rem **************************************************************** @rem Please alter the next lines to include the alternate data streams. powershell Compress-Archive -Path .\ADSTester.txt -Update -DestinationPath ADSTester.zip powershell Expand-Archive -Path ADSTester.zip -DestinationPath .\Extracted\ dir /r Extracted\ADSTester.txt @rem Only one file left :-( pause  
    • By Mudoch
      I need to replace a desktop applications functionality. I'll call it App "A".
      The application has defined 2 hot keys one that toggles between it and another window, App "B", and one that triggers keystrokes to App "B" to get data where App "A" can access it. Then tells app "A" to fire off processing of data.. Unfortunately when App "B" is a 64bit application this functionality no longer works. 
       
      For now I've hobbled together a work a round solution by using 2 apps with what appears to be similar abilities. AutoIt and a desktop application that allows me to define the 2 hot keys. The SutoItX Dll is great for my processes within App "A" as it uses VBA for event driven tasks.
      The second app allows me to define the Hot keys and which windows they belong to.
      My fail is on how to use AutoIT to define the hot Keys and link to specific windows.
      So as I see this working:
                App "A" launches and fires off internal VBA code that in turn sets up HotKeys. If App "B" is not found code shuts down without enabling the hotkeys.  
                A hot key of CTRL-F1 toggles, activates window, back and forth between App "A and "B"  So the hotkey is captured only when either App "A" or "B" is currently the active focus. and swaps the active focus application window.
                A hot key of CTRL-F2 from App "B", Send Key strokes to App "B" to place App "B" windows' content into windows clip board then switch to App "A" and send a keystroke, CTRL-F3, to trigger processing the clip board through App "A"'s normal event handlers.  App "A" already knows that CTRL-F3 means to run custom VBA code to process the clipboard.
      Any help would be appreciated here, thanks.  
    • By ur
      Which Powershell command in the PowerCLI module for VMware ESX used to interact with UI apps?
       
      When I launch any exe/any exeutable using powercli on guest VM using powercli command.
      Invoke-VMScript, I am able to run them in the background but not in the foreground.
       
      i.e., UI apps are not launching but showing the background as running in the task manager.
       
      We need our UI Automation scripts to execute in the VM, but it is not working.
       
      We are able to do in virtualbox and hyper-v but not in vmware esx using powercli.
       
      Please suggest.
    • By ambad4u
      Hello and Good Day to All!
      I am trying to install .NET 3.5 on Windows 10 x64bit via autoit (via ShellExecuteWait + PowerShell).
      If I run this line, it will runs without issues:
      ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & @ScriptDir & '\OJP83BU523.ps1' & '"') "OJP83BU523.ps1" contains: DISM /Online /Enable-Feature /FeatureName:NetFX3 /All /Source:D:\Sources\sxs /LimitAccess
      However, since I won't know in advance the drive letter of the "sources" folder, I created a script to generate a PowerShell Script to give a correct path for it.
      With the modified script below, PowerShell only blinks and nothing happens
      ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & @ScriptDir & '\' & $filename & '"') or
      ShellExecuteWait('PowerShell.exe', '-executionpolicy Bypass -File "' & $filename & '"')  
      I wish I know the difference with "$filename" and "\OJP83BU523.ps1" usage, as for me, it should be the same.
      Attached is my entire autoit script.
      any help is appreciated!, many thanks in advance!
      test.au3
    • By JLogan3o13
      There are a number of posts on the forum regarding use of Selenium in AutoIt. I recently had a go at using the PowerShell Selenium module, and was amazed at how easy it is. Thought I would post an example here; if anyone is interested this could probably be incorporated into AutoIt code pretty easily. 
      Pre-Req - The true star of this script is the ChroPath extension, available for Edge, Chrome and FireFox. With it installed, you just click on the element, select Inspect, and then ChroPath generates the XPath to the element for you. Here is an example based on a simple form I created on one of my sites.
      $myForm = Start-SeChrome -StartURL "http://logancomputerser.com/Appointment.html" -Maximized $firstName = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_First']" $lastName = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_Last']" $address = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_Street1']" $city = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_City']" $zip = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_Zip']" $state = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//select[@id='formElement_State']" $phoneDay = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_DaytimePhone']" $phoneNight = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_EveningPhone']" $email = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_liamE']" $user = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_48564']" $pw = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='formElement_f403c']" $submit = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='wstForm_Contact_Submit']" $reset = Find-SeElement -Driver $myForm -Timeout 30 -XPath "//input[@id='wstForm_Contact_Reset']" Send-SeKeys -Element $firstName -Keys "Joe" Send-SeKeys -Element $lastName -Keys "Blow" Send-SeKeys -Element $address -Keys "111 S. Main St." Send-SeKeys -Element $city -Keys "AnyCity" Send-SeKeys -Element $zip -Keys "90210" Send-SeKeys -Element $state -Keys "CA" Send-SeKeys -Element $phoneDay -Keys "555.867.5309" Send-SeKeys -Element $phoneNight -Keys "555.888.1212" Send-SeKeys -Element $email -Keys "1Adam12@gmail.com" Send-SeKeys -Element $user -Keys "JBlow" Send-SeKeys -Element $pw -Keys "MyPassword" Start-Sleep 1 Invoke-SeClick -Element $submit Stop-SeDriver -Driver $myForm  
      As mentioned, this is just another way to skin the cat, but I found it a pretty fast way to initiate some easy testing in Selenium, and have used it a couple of times in projects now, both straight through PowerShell and wrapped in AutoIt.
×
×
  • Create New...