Execute script dynamically with a script's converted exe? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Execute script dynamically with a script's converted exe?

Post by william_ahk » 25 Jan 2022, 01:18

Is it possible to execute a script file or code with the compiled script's exe? Passing parameters to run .ahk files just like the AutoHotkey binary?

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Execute script dynamically with a script's converted exe?

Post by mikeyww » 25 Jan 2022, 07:05

Yes, you can write your own interpreter and compile it! :)

You can rename AutoHotkey.exe to something else, give your AHK script file the same name with .ahk extension, put the two files in the same directory, and then run the renamed EXE file.

Also this capability: https://www.autohotkey.com/docs/Scripts.htm#ahk2exe-base
[v1.1.34+]: The standard AutoHotkey executable files can also be used as the base of a compiled script, by embedding a Win32 (RCDATA) resource with ID 1. This allows the compiled script .exe to be used with the /script switch to execute scripts other than the main embedded script. For more details, see Embedded Scripts.

william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Re: Execute script dynamically with a script's converted exe?

Post by william_ahk » 25 Jan 2022, 08:40

@mikeyww Thanks! Using the /script switch to make the compiled script exe execute scripts other than the main embedded script sounds exactly what I needed. However when I try to select an exe for the base file it says the exe is invalid, any ideas?
Ahk2Exe_2022-01-25_21-36-58.png
Ahk2Exe_2022-01-25_21-36-58.png (7.52 KiB) Viewed 692 times

User avatar
mikeyww
Posts: 26931
Joined: 09 Sep 2014, 18:38

Re: Execute script dynamically with a script's converted exe?

Post by mikeyww » 25 Jan 2022, 09:08

I actually never tried this, just saw the documentation. You might need to follow what is in "Embedded Scripts", step by step. Others here may know the trick.


TAC109
Posts: 1112
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Execute script dynamically with a script's converted exe?  Topic is solved

Post by TAC109 » 25 Jan 2022, 15:34

@william_ahk
If you are using the latest beta Ahk2Exe from here (which was originally compiled with the test version of AutoHotkey 1.1.34.00) you can compile your first script using Ahk2Exe.exe itself as the base file. You can then use this .exe with the /script parameter to run another script. Unfortunately this is U32 only.

If you need U64 then you will need to download the test version of AutoHotkey 1.1.34 from here and use the extracted AutoHotkeyU64.exe as the base file for your compile, still using the beta version of Ahk2Exe mentioned earlier. The /script parameter can then be used with the resulting .exe.

Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe

william_ahk
Posts: 493
Joined: 03 Dec 2018, 20:02

Re: Execute script dynamically with a script's converted exe?

Post by william_ahk » 26 Jan 2022, 01:32

@swagfag @TAC109 Thank y'all!

Post Reply

Return to “Ask for Help (v1)”