pztlmx

How to convert AutoIT and AutoHotKey script to Powershell ?

6 posts in this topic

#1 ·  Posted

HI,

Having several AutoIT and AutoHotKey Scripts. How can I in a fast and smooth way convert these to PowerShell scripts (.ps1) ??

Would be nice if there were a function, where you could export the script to PowerShell ?

 

Best regards,

Jan Larsen / IBM

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

@pztlmx yes, it would be great. It would also be nice if you could convert batch files to fully functional python with a click of a button, but it doesn't work that way. Powershell and AutoIt are vastly different languages, with different syntax and abilities. There are some options if you search the forum for using AutoItX to call AutoIt in PS, as well as running powershell commands from an AutoIt script, but you're not going to find a one-button convert/export feature.

Edit: try this one for running PS commands in AutoIt, by our benevolent leader:

 

Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted

Thanks.
Will take a look...

/Jan.

Share this post


Link to post
Share on other sites

#4 ·  Posted

On 7/6/2017 at 8:54 AM, pztlmx said:

Thanks.
Will take a look...

/Jan.

Using the AutoIT powershell cmdlets is very much a trial and error process, as the cmdlets do not have any help file content, so you will have to make educated guesses as to what each function does until you find the functions that perform the action you are looking for.

Share this post


Link to post
Share on other sites

Sure this is possible using the AutoITObject Server

Quote

What you'll find there is folder named AccessAutoIt. Unzip it somewhere and inside there will be five files: AutoItObject.au3 (1.2.8.0), AutoItServer.au3, Csharp.cs, JS.js and VBS.vbs.

CLS

# AutoIT Object instantition
[reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$oAutoIt = [Microsoft.VisualBasic.Interaction]::GetObject("AutoIt.Application")
$oAutoItType = $oAutoIt.GetType()

$WS_OVERLAPPEDWINDOW = [System.Convert]::ToInt64("00CF0000", 16) # 0x00CF0000

$hGui = $oAutoIt.Call("GUICreate", "PS AutoIt GUI test", -1, -1, -1, -1, $WS_OVERLAPPEDWINDOW)
$hButton = $oAutoIt.Call("GUICtrlCreateButton", "Click", 100, 100, 100, 30)
$hButton2 = $oAutoIt.Call("GUICtrlCreateButton", "Click me too", 100, 300, 100, 30)

$WS_OVERLAPPEDWINDOW.GetType().Name

$oAutoIt.Call("WinSetOnTop", "PS AutoIt GUI test", "", 1)

$oAutoIt.Call("GUISetState")

$AW_FADE_IN = [System.Convert]::ToInt64("00080000", 16) # 0x00080000
$oAutoIt.Call("DllCall", "user32.dll", "bool", "AnimateWindow", "hwnd", $hGui, "dword", 1000, "dword", $AW_FADE_IN)

$Dummy = -3
Do{
    if($oAutoIt.Call("GUIGetMsg") = -3)
        {Exit}

    Elseif($hButton)
        {$oAutoIt.Call("MsgBox", 262144+32+3, "Title", "Bzzz bzz bzzzz", 0, $hGUI)}

    Elseif($hButton2){$oAutoIt.Call("Beep", 500, 700)}


    sleep(1)
}
Until($Dummy)

$oAutoIt.Call("GUIDelete")

If( $oAutoIt.Call("MsgBox", 4 + 48 + 262144, "?", "Kill server?") = 6)
  { $oAutoIt.Quit}

I quickly translated the vbscript Example into PowerShell...

The events are not working well as expected but this is just a matter of passing the correct paramaters to the GUIGETMSG loop. PowerShell does a differenct Type casting of the Hex values apparently then vbscript and AutoIT.

See original thread  https://www.autoitscript.com/forum/topic/128627-access-autoit/#comment-892581 first post there are more examples on have to ...

Rgds

ptrex

Share this post


Link to post
Share on other sites

This are just some  native AutoIT functions that are reused in PowerShell (using AutoITObject)

1. ToolTip Example

2. Random Example

3. MemGetStats Example

CLS
Write-host "Watch the ToolTip on your Screen ! "
# AutoIT Object instantition
[reflection.assembly]::LoadWithPartialName("'Microsoft.VisualBasic")
$oAutoIt = [Microsoft.VisualBasic.Interaction]::GetObject("AutoIt.Application")
$oAutoItType = $oAutoIt.GetType() 

$im = [reflection.bindingflags]::InvokeMethod
$gp = [reflection.bindingflags]::GetProperty 

$oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", "Some cool text from AU3 !!! ",900, 400))
#$oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("Beep", 500, 700))
$oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("Sleep", "2000"))
$oAutoItType.InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", ""))

# Or the short version
$oAutoIt.GetType().InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", "Some cool text",900, 400))
$oAutoIt.GetType().InvokeMember("Call", $im, $null, $oAutoIt, ("Sleep", 3000))
$oAutoIt.GetType().InvokeMember("Call", $im, $null, $oAutoIt, ("ToolTip", ""))


Write-host ""
# Call Random Number Function
Write-host "Random Nr  : " $oAutoIt.GetType().InvokeMember("Call", $im, $null, $oAutoIt, ("Random",1,100,1))

Write-host ""
Write-host "Memory Stats : "
$aArray = $oAutoIt.GetType().InvokeMember("Call", $im, $null, $oAutoIt, ("MemGetStats"))

For($i=0
    $i -le 5
    $i++)
    {
     switch ($i) {
        0 {"Memory Load : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        1 {"Total physical RAM : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        2 {"Available physical RAM : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        3 {"Total Pagefile : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        4 {"Available Pagefile : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        5 {"Total virtual : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        6 {"Available virtual : $([Math]::round(($aArray[$i]/ 1MB),2)) Gb" ; break} 
        default {"Something else happened"; break}
       }
     }

Enjoy !

ptrex

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