Jump to content

How to convert AutoIT and AutoHotKey script to Powershell ?


pztlmx
 Share

Recommended Posts

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

Link to comment
Share on other sites

  • Moderators

@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

"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 comment
Share on other sites

  • 2 weeks later...
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.

Link to comment
Share on other sites

  • 2 months later...

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

Link to comment
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

Link to comment
Share on other sites

  • 3 months later...
  • Developers
55 minutes ago, DynamicRookie said:

 

i know this was already answered, i need more posts.

Don't or you will be setback to zero as my first deed in 2018!!!!

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Moderators

Agreed. @DynamicRookie stating outright that you are needlessly padding your post count is akin to waving a sign that screams "Ban me please". The forum rules ask above all that members exercise some common sense - I would suggest you think about it before your next post.

"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 comment
Share on other sites

13 minutes ago, JLogan3o13 said:

. The forum rules ask above all that members exercise some common sense - I would suggest you think about it before your next post.

Oh wow chill it was a joke meaning that my post was kind of pointless.

Also, why the indirect insult, Why not just telling me to dont do it.

 

I just said i need more posts, not that i'm grinding for them, i am not manipulating in any way the forum features, as the rules say:

 

Quote
  • Automated manipulation of polls, user reputation or other forum features.

 

With typing a post that has relation with the main thread theme, is not manipulating, i am just telling my opinion and saying that i need more posts, a re-roll of my posts would be justified if my post was some kind of spam, pointless text, or a message with no relation with the thread, which is not

 

So 

Quote

I would suggest you think about it before your next post.

 

Edited by DynamicRookie
Link to comment
Share on other sites

  • Moderators

No insult - simply stating what the forum rules specifically ask for, common sense. 

Quote

Use common sense. If you do not have common sense, don't do anything.

As for it being a joke, you have two of the three Mod staff stating it wasn't a funny one :)

"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 comment
Share on other sites

  • Moderators

DynamicRookie,

Make it all three.

M23

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

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...