Jump to content

Using the AutoIt PowerShell Cmdlets


Recommended Posts

  • Administrators

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

Link to post
Share on other sites
  • 1 month later...

Please add this to AutoItX HelpFile.

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * 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 * Include Dependency Tree (Tool for analyzing script relations) *

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 * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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 TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE *

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2021-10-18

Link to post
Share on other sites
  • 2 months later...
  • 7 months later...
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.

Link to post
Share on other sites
  • 4 months later...
  • 3 years later...

Hi there. I have some questions.

Where i can read the documentation of the each cmdlet from the first post?

What is the name of cmdlet, that provides PixelGetColor? 

Which cmdlet can detect mouse click and kb button click?

Thanks.

Link to post
Share on other sites
  • Moderators

@Sallyy if you want to read the help file on each cmdlet, install the module in PS, then look at the help text. Or open the .chm file in the directory where AutoItX is installed.

As for PixelGetColor and MouseClick, as the first post clearly states, not all AutoIt functions have been translated to cmdlets. Install the module, what you see is what you get.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to post
Share on other sites
  • 7 months later...

The help text on each cmdlet is just the parameter sets available, no examples, nada.

How I worked around this is using the AutoIt help online under Functions.  Easy to find the appropriate help topic once you understand the organization of the functions.

e.g. Get-AU3WinHandle -> WinGetHandle

Would be nice to have the help incorporated into the cmdlets themselves but I understand that is a lot of work.  Be sure to unblock all the files if you are having problems.

Edited by PoSH
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By HoratioCaine
      Hi, everyone.
      I have python code for kill window,  but sometimes it does not working .

      My code is :
      import subprocess import time import ctypes au3_dll = ctypes.windll.LoadLibrary(r'D:\AutoIt\AutoItX3.dll') def close_ie(title): subprocess.Popen(f"C:/Program Files (x86)/Internet Explorer/iexplore.exe https://cn.bing.com/?mkt=zh-CN") time.sleep(2) au3_dll.AU3_Opt("WinTitleMatchMode", 2) ret = au3_dll.AU3_WinKill(title, "") print(ret) if __name__ == '__main__': title = '必应 - Internet Explorer' for i in range(10): close_ie(title) My expectation is that all IE windows will be closed, but there will always be a few windows still there.
      My env: win10 64bit python3.6.4 autoit v3.3.14.2  
      Any suggestions would be appreciated 
    • By DannyJ
      $sCommands1 = 'powershell.exe Get-ChildItem' $iPid = run($sCommands1   , @WorkingDir , @SW_SHOW , 0x2) $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) ConsoleWrite("$sOutput") ConsoleWrite($sOutput) ConsoleWrite(@CRLF) $aOutput = stringsplit($sOutput ,@LF , 2) For $i=0 To  UBound($aOutput) - 1 Step 1     ConsoleWrite($aOutput[$i]) Next The script above reads the whole directory into a one dimensional array, but I need to work with the array, so I need to split the array into multiple dimensions.
      I have already read some forum answers here, and I have already tried these commands:
       
      Are there any way to use the $aOutput variable like in PowerShell:
      PowerShell:
      $a = Get-ChildItem $a.Mode I imagine this in AutoIt  $aOutput
      ConsoleWrite($aOutput[i].Mode) Or if I split this command into 2 dimension like:
      For $i To UBound($aOutput)-1 Step 1 ConsoleWrite($aOutput[$i][1]) ConsoleWrite($aOutput[$i][2]) Next  
    • By DannyJ
      If I try to run this script with   Get-ChildItem which means dir this script works perfectly, but If I try to run this command Get-RDUserSession, my script has the following error message:
      This command runs perfectly in PowerShell admin and I get back the values
      Get-RDUserSession -ConnectionBroker  broker.local | sort Username Or you can try this command as well
      Get-Command Get-RDUserSession If I run the above mentioned command this runs perfectly in PowerShell but not with AutoIt.
      Here is my script you can test the commands:
      #include<array.au3> $iPid = run('powershell Get-Command Get-RDUserSession'  , @WindowsDir , @SW_HIDE , 0x2) ;; This command not works in AutoIT you can test it in PowerShell but it won't work in Autoit ;$iPid = run('powershell Get-RDUserSession -ConnectionBroker  broker.local | sort Username'  , @WindowsDir , @SW_MAXIMIZE , 0x2) ; This command not works in AutoIT ;$iPid = run('powershell Get-ChildItem | sort Name'  , @WindowsDir , @SW_HIDE , 0x2) ; This runs perfectly $sOutput = ""  While 1     $sOutput &= StdoutRead($iPID)         If @error Then             ExitLoop         EndIf  WEnd ;~ msgbox(0, '' , $sOutput) $aOutput = stringsplit($sOutput , @LF , 2) _ArrayDisplay($aOutput)  
      That could be the solution of the problem if I could run, directly this PowerShell command window and Write to it and save it's values.
    • By DrLarch
      I'm trying to run this powershell command from Autoit and can't figure out how to pull it off:
      Get-ProvisionedAppxPackage -Online | Where-Object { $_.PackageName -match "xbox" } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName } I've been trying to run it many different ways including:
      $sCMD = 'Get-ProvisionedAppxPackage -Online | Where-Object { $_.PackageName -match "xbox" } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }' RunWait(@comspec & ' /c powershell.exe -nologo -executionpolicy bypass -noprofile -Command "&' & $sCMD & '"') The problem is that it seems I'm missing something in how to escape or double the quotes. I've tried doubling the quotes in many different ways, but the end result always produces a syntax error in powershell. I could just run powershell first, then paste and run the command, then close the powershell window, but that's clunky. I'm trying to do it either via parameter (as above) or in one line like this:
      RunWait(@comspec & ' /c powershell.exe -nologo -executionpolicy bypass -noprofile -Command "&Get-ProvisionedAppxPackage -Online | Where-Object { $_.PackageName -match "xbox" } | ForEach-Object { Remove-ProvisionedAppxPackage -Online -AllUsers -PackageName $_.PackageName }"')  
    • By antonioj84
      any assistance how to incorporate this powershell command within autoit
       
      powershell.exe -nologo -executionpolicy bypass -WindowStyle hidden -noprofile -command "&Set-WinUserLanguageList -LanguageList fr-CA, en-CA -Force"
×
×
  • Create New...