Use AutoHotkey to run scripts with "robin.exe"

At @jpap’s suggestion, I’m adding this guide, closely related to another post, which can probably be deleted.

Here is a way to run Robin.exe with AutoHotkey, which is very useful for RPA tasks.

AutoHotkey can provide ad hoc methods for automation scenarios that are difficult or impossible to address using only the standard language of a platform. Powershell, python, AutoIT, VBScript, REXX and the various C# scripting languages, among others, are extremely helpful for RPA as well. They all have their strengths and weaknesses.

Problem: How can I create an executable (.exe, that is) that will run a Robin script without calling Robin.Editor? (@jpap has provided one way in another post, using C#, and I’m looking forward to the Powershell version too :slight_smile: ) .

Sub-problem: At least on my system, running a desktop automation script via Robin.exe from the command line leaves two (2) instances of conhost.exe running, and two (2) instances of Robin.BridgeToUiAutomation.exe running. This might create issues if many scripts are run without garbage collection.

Here are shots from Win7 Task Manager showing where “conhost.exe” and “Robin.BridgeToUiAutomation.exe” would show up on my system if they were running:

conhost%20before

and

uibridge%20before

Now I’ll run a script from the command line, like so:

C:>robin run C:\Users\burque505\Documents\Robin\notepad4.exe

The script executes without a problem.

Here are some screenshots of what’s left running afterwards:

conhost%20after

and

uibridge%20after

What to do?

Partial solution: Autohotkey script (uncompiled):

; +-----------------------------------+
; ¦  run as admin                     ¦
; +-----------------------------------+

full_command_line := DllCall("GetCommandLine", "str")

if not (A_IsAdmin or RegExMatch(full_command_line, " /restart(?!\S)"))
{
    try
    {
        if A_IsCompiled
            Run *RunAs "%A_ScriptFullPath%" /restart
        else
            Run *RunAs "%A_AhkPath%" /restart "%A_ScriptFullPath%"
    }
    ExitApp
}

; +------------------------+
; ¦  Run the Robin script  ¦
; +------------------------+
RunWait, cmd.exe /c robin.exe run %A_MyDocuments%\Robin\notepadex4.robin

; +-----------------------------------------------------------+
; ¦  Clean up conhost.exe and Robin.BridgeToUIAutomation.exe  ¦
; ¦  created by above process.                                ¦
; ¦                                                           ¦
; +-----------------------------------------------------------+

Process, Exist, conhost.exe
Process, Close, %ErrorLevel%
; ErrorLevel contains the process ID. I won't go into AutoHotkey syntax,
; which some have described in unkind terms :). You get used to it.

Process, Exist, conhost.exe
Process, Close, %ErrorLevel%

Process, Exist, Robin.BridgeToUIAutomation2.exe
Process, Close, %ErrorLevel%

Process, Exist, Robin.BridgeToUIAutomation2.exe
Process, Close, %ErrorLevel%

; Please add these lines below if you intend to compile the script.
; It will not hurt to leave them in, regardless.

Process, Exist, Robin.BridgeToUIAutomation2.exe
Process, Close, %ErrorLevel%

The instances of conhost.exe and Robin.BridgeToUiAutomation are gone. In the process above, as briefly referred to in comments in the code, calling

Process, Exist, conhost.exe

causes the process ID to be stored in the built-in Autohotkey variable “ErrorLevel”. Due to the syntax requirements of Autohotkey, this variable needs to be enclosed in “%” symbols to get the value, as in

Process, Close, %ErrorLevel%

right below it. So far so good.

Further steps: You probably want an executable, not just another script to run, which to some extent defeats your purpose. AutoHotkey provides a couple of ways to compile scripts such as the one above (visit the AutoHotkey site for lots more info).

The “compiled” script actually contains an instance of the AutoHotkey executable which runs the script. Compiling in optional resources can be done, but isn’t trivial. Perhaps the easiest thing to do, which has the advantage of easier script maintenance, is to include the *.appmask and *.robin scripts in the same folder as the executable. On my machine, the files in the folder look like this:

(For my script above, I had to add an extra

Process, Exist, Robin.BridgeToUIAutomation2.exe
Process, Close, %ErrorLevel%

at the end of script, as it was leaving either leaving an instance of Robin.BridgeToUiAutomation.exe or creating an extra one, not sure which. :grinning:)

I replaced the executable’s icon to the Robin icon with Resource Hacker because it’s really easy to do. but there are other ways.

You can use Task Scheduler to avoid the UAC prompts. One of the better guides for this is in the link.

I look forward to your experiences with this and comments.

Regards,
burque505

2 Likes