Error opening the destination file ahk

Page 1 of 2 - Error: Error opening the destination file - posted in Ask for Help: I have used AHK before on my desktop to launch putties. Now I have set up a laptop instead, and I can no longer compile my AHK scripts. I get a error, Ahk2Exe Error ---------------------------------------------- Error: Error opening the destination file. ---------------------------------------------- I also tried to compile a empty script that I made just by right clicking -> new -> autohotkey scr...

  • Members
  • 3 posts
  • Last active: Apr 30 2008 01:22 AM
  • Joined: 29 Apr 2008

I have used AHK before on my desktop to launch putties.

Now I have set up a laptop instead, and I can no longer compile my AHK scripts. I get a error,

Ahk2Exe Error
———————————————-
Error: Error opening the destination file.
———————————————-

I also tried to compile a empty script that I made just by right clicking -> new -> autohotkey script. Same error.

I have AVG installed, and I disabled it. Still same error.

I also rebooted, and reinstalled the latest AHK. (I had previously installed the original EXE I had used successfully before). No good.

I searched for «opening the destination file» «won’t compile» but I can’t find any topics addressing this issue.

Thanks!

#1

Posted 29 April 2008 — 08:35 PM

  • Back to top



SomeGuy

  • Members
  • 86 posts
  • Last active: May 17 2008 10:33 PM
  • Joined: 21 Apr 2008

sounds like the exe is in use.

#2

Posted 29 April 2008 — 08:36 PM

  • Back to top



vctralsh

  • Members
  • 3 posts
  • Last active: Apr 30 2008 01:22 AM
  • Joined: 29 Apr 2008

Hrm,

I have deleted the EXEs that are corrupt (after that error message shows up) and rebooted as well. Is it possible that the EXE could be in use after a reboot? Also when I make new files from the right click menu, those get the same error, but none of those would have a corresponding EXE in existence yet.

#3

Posted 29 April 2008 — 09:44 PM

  • Back to top



sinkfaze

  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008

Where are you trying to write the script to? Check the folder you’re writing to to see if it has any attributes like Hidden or Read Only.

#4

Posted 30 April 2008 — 03:35 AM

  • Back to top



engunneer

  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005

are you running vista? are you trying to compile inside «program files»?

#5

Posted 30 April 2008 — 03:45 PM

  • Back to top



vctralsh

  • Members
  • 3 posts
  • Last active: Apr 30 2008 01:22 AM
  • Joined: 29 Apr 2008

I am running WinXP home.

I tried to compile on the desktop, as well as in a folder on the desktop.

#6

Posted 12 May 2008 — 09:23 PM

  • Back to top



sinkfaze

  • Moderators
  • 6367 posts
  • Last active: Nov 30 2018 08:50 PM
  • Joined: 18 Mar 2008

Check the properties of the Autohotkey folder in C:Program Files and see if it is set to read only; if it is, remove that attribute. Also check the Compiler folder inside the Autohotkey folder and make sure it is not set to read only.

#7

Posted 12 May 2008 — 11:19 PM

  • Back to top



copa_ahk

  • Members
  • 28 posts
  • Last active: Aug 16 2016 08:40 AM
  • Joined: 14 Jun 2005

@vctralsh, have you fixed it ?

I have the same problem since today on my laptop.
(a HP with win Xp Home),

i had installed «Compile with options» some days ago ??
oh yeah, and XP SP3 ???

btw it also happens when there is no exe in the folder.
It is created «a bit» but then after a few seconds there comes a message «Ahk2Exe Error: Error opening destiontion file»

Will try to find the solution as well….

edit:
SOLVED somewhat:

I can compile again when I disable AVGs «Resident Shield»

#8

Posted 23 May 2008 — 08:24 PM

  • Back to top


  • Guests
  • Last active:
  • Joined: —

Same Problem…

Disabling AVG Resident Sheild Solves it…

Excluding the Path that contains the AHK file also solves it.

@vctralsh, have you fixed it ?

I have the same problem since today on my laptop.
(a HP with win Xp Home),

i had installed «Compile with options» some days ago ??
oh yeah, and XP SP3 ???

btw it also happens when there is no exe in the folder.
It is created «a bit» but then after a few seconds there comes a message «Ahk2Exe Error: Error opening destiontion file»

Will try to find the solution as well….

edit:
SOLVED somewhat:

I can compile again when I disable AVGs «Resident Shield»

#9

Posted 17 July 2008 — 09:25 AM

  • Back to top


Gadget

  • Guests
  • Last active:
  • Joined: —

With the same problem and running AVG Version 8, I could go into the Resident shield to add an exception. The directory I chose was that where the script is being compiled to an exe.

#10

Posted 26 February 2009 — 03:04 PM

  • Back to top



Drugwash

  • Members
  • 1078 posts
  • Last active: May 24 2016 04:20 PM
  • Joined: 07 Sep 2008

This probably happens because of UPX. Try to (temporarily) remove upx.exe from the compiler folder and see if the error persists.

Some AV software falsely regard UPX and the files compressed with it as a potential threat and block them.

#11

Posted 26 February 2009 — 06:37 PM

(AHK 1.0.48.05 and Win98SE) forever | My scripts are here

  • Back to top



AndyDenn

  • Members
  • 1 posts
  • Last active: Mar 01 2009 05:10 PM
  • Joined: 01 Mar 2009

I am having the same problem, also running avg.

Here is my workaround:
From the command-line:

«c:Program FilesAutoHotkeyCompilerAhk2Exe.exe» /in MyScript.ahk /out MyScript.xxx

rename MyScript.xxx MyScript.exe

This trick does not work from the GUI, since the GUI always appends .exe

#12

Posted 01 March 2009 — 05:34 PM

  • Back to top


Shassi

  • Guests
  • Last active:
  • Joined: —

Hi, same probleme with AVG, solved by putting the script’s folder in AVG exception list.

#13

Posted 10 March 2009 — 10:35 PM

  • Back to top


Fred

  • Guests
  • Last active:
  • Joined: —

I have AVG also, but didn’t report anything,

Desktop was READ-ONLY… just that…

Greetings.

#14

Posted 18 March 2009 — 06:15 PM

  • Back to top


killerstorm2

  • Guests
  • Last active:
  • Joined: —

Check the properties of the Autohotkey folder in C:Program Files and see if it is set to read only; if it is, remove that attribute. Also check the Compiler folder inside the Autohotkey folder and make sure it is not set to read only.

Do this, it works fine….
Go to program files then to right click on autohotkey folder, then remove the «read only» and it should work fine.

#15

Posted 24 July 2009 — 08:30 AM

  • Back to top


Содержание

  1. Error: Error opening the destination file
  2. Error opening the destination file ahk
  3. Re: Ahk2Exe unable to create destination file
  4. Re: Ahk2Exe unable to create destination file
  5. Re: Ahk2Exe unable to create destination file
  6. Re: Ahk2Exe unable to create destination file
  7. Re: Ahk2Exe unable to create destination file
  8. Re: Ahk2Exe unable to create destination file
  9. Re: Ahk2Exe unable to create destination file
  10. Re: Ahk2Exe unable to create destination file
  11. Re: Ahk2Exe unable to create destination file
  12. Re: Ahk2Exe unable to create destination file
  13. Error when I compile a .ahk script

Error: Error opening the destination file

I am having the same problem, also running avg.

Here is my workaround:
From the command-line:

«c:Program FilesAutoHotkeyCompilerAhk2Exe.exe» /in MyScript.ahk /out MyScript.xxx

rename MyScript.xxx MyScript.exe

This trick does not work from the GUI, since the GUI always appends .exe

  • Members
  • 237 posts
  • Last active: Nov 10 2016 05:01 PM
  • Joined: 10 Nov 2005

For me this problem was caused by AVG. I’ve experienced this issue in versions 7, 8 and 9 of AVG. I’ve tried adding the Autohotkey’s folders and files to the exclusion list, but this doesn’t seem to work. The only work around i have is to temporarily disable AVG’s Resident Shield, then compile, then re-enable.

I hope this helps.

  • Guests
  • Last active:
  • Joined: —

  • Guests
  • Last active:
  • Joined: —

Using AHK_L-related files downloaded around 2011-11-16, trying to compile a .ahk file using Ahk2Exe for AHK_L v1.1.05.01 I also got:

Error: Error opening the destination file

on Windows XP SP3 (32-bit) and Windows 7 (64-bit).

In my case it turned out that leaving the «Base File (.bin)» drop down as (Default) appeared to be the problem. Setting this to any of the other values would produce an executable (no error). (To reproduce, it appeared necessary to delete an existing compiled results of ahk2exe.)

The following filenames and associated MD5 checksums are included for reference:

Ahk2Exe.exe (for AHK_L v1.1.05.01) : FB436762F5D18FFB56C9C14572DC44FE
AutoHotkey.exe (AHK_L): A6DD7D5DA868E3137E31A5653B59C7EB
ANSI 32-bit.bin: 09E3353FB820F57148E36BD595DDF17B
Unicode 32-bit.bin: C9CA8048A7A786FAD367714FE9FF920B
Unicode 64-bit.bin: 182E26E35C0694EE87389AA5448B632C

  • Guests
  • Last active:
  • Joined: —

  • Members
  • 2 posts
  • Last active: Nov 14 2014 03:28 PM
  • Joined: 30 Oct 2014

The exe I created and had been using vanished when I went to run it this morning and I wa s unable to compile it again due to the «Error: Error opening the destination file» after which a search brought me here for a solution.

I am running Avast so AVG has nothing to do with it. Tried the properties changes from read only with no luck for that matter they changed right back all on their own in Windows 7 64 bit. Tried disabling «File System Shield» in Avast with no change.

What finally did the trick was similar to what was mentioned above: «In my case it turned out that leaving the «Base File (.bin)» drop down as (Default) appeared to be the problem.» In my case setting this to «Unicode 32 bit» did the trick. Setting it to «ANSI» did not work. I didn’t try 64 bit.

Then I had to flush the Icon Cache to get my Icon back that I had included for the exe which vanished. That was done by running the command «ie4uinit.exe -ClearIconCache» without the quotation marks from the command prompt.

Hope this helps someone. Couldn’t resist the smilies

Источник

Error opening the destination file ahk

I’m using Ahk2Exe regularly but today it fail compiling me script, returning the error: «Error: Error opening the destination file.»

I’m using the compiler in command-line mode. I’m creating the exe file on a DropBox folder but had the same error when trying on another drive. There is no disk space issue.

Any idea what could cause this error?

Re: Ahk2Exe unable to create destination file

I often get problems with file operations (in generals) on dropbox folders, try to pause syncing or use another folder.

Re: Ahk2Exe unable to create destination file

Re: Ahk2Exe unable to create destination file

Thanks for the reply. I tried these 2 solutions with the same result.

But I just tried disabling Windows Defender real-time protection and then it worked. So this seems to be a conflict with Windows Defender.

I’d prefer to find a solution in order to be able to compile without having to turn the protection off. Since I’m compiling using a batch file, maybe there is a command line to disable Windows Defender before compiling and re-enable it after. but this is not the forum for this question 😉

Re: Ahk2Exe unable to create destination file

Re: Ahk2Exe unable to create destination file

Our messages crossed. I was testing it with Windows Defender instead of reading your reply 🙂

So, to continue on my previous message, I added a folder exception to the Windows Defender config so I should be OK now.

And thanks TAC109 for the link to the other thread. I should have search better before.

Re: Ahk2Exe unable to create destination file

Re: Ahk2Exe unable to create destination file

Re: Ahk2Exe unable to create destination file

Thanks for doing this. I tested your compiled version with a sample script saved on my Dropbox with Defender enabled and it worked.

However, I must say that the issue I reported yesterday was with an older version of the Ahk2Exe-edge compiler customized for my development pipeline. So, I could not confirm that the new version would work as a replacement of my old version in my custom environment. When I find time to tweak your new version, I’ll follow-up here.

Re: Ahk2Exe unable to create destination file

Ahh. If you’re using an older Ahk2Exe-edge version created by fincs , it won’t using your %temp% directory for generating the .exe. In your case Ahk2Exe will be using the Dropbox folder as you indicated before. (This use of %temp% was one of the changes I migrated from Ahk2Exe-master back when I started work on the new version.)

I too, used to get similar errors when I compiled into a Dropbox folder, so the problem may not have been anti-virus related.
Cheers

Re: Ahk2Exe unable to create destination file

@JnLlnd
Further to my last reply, here is a little script I used to use to run the old Ahk2Exe-edge by fincs . You might find it useful to avoid Dropbox problems. It also provides for new versions of Autohotkey, and new versions of this script.

I had the edge compiler installed in the standard C:Program FilesAutoHotkeyCompiler as Ahk2Exe1.exe .

I had this script called Ahk2Exe.ahk in my source folder.

If I had a new version of this script I would compile it with default parameters so the compiled version was in the source folder. Then I ran the source Ahk2Exe.ahk, which copied Ahk2Exe.exe from the source folder to C:Program FilesAutoHotkeyCompiler .

After installing a new version of AutoHotkey, I would again run the source Ahk2Exe.ahk (without compiling first). This would re-set my compiled script to be the official Ahk2Exe.exe

After that, all compiles could proceed normally. All compiles of other scripts could be started by running C:Program FilesAutoHotkeyCompilerAhk2Exe.exe in any of the standard usual ways.

(Please excuse the quality of the program code! it was early days for me with Ahk.)

Источник

Error when I compile a .ahk script

Every time that I try to compile a .ahk script I get an error message in a message box :

Error: Error openning the destination file

I can see the .exe file appear in the target folder but it disappears when I quit the message box.

What am I doing wrong ?

  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

  • Guests
  • Last active:
  • Joined: —

  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

Still no need to compile 😉

— Create a dir
— copy autohotkey.exe and rename yourfancyname.exe
— copy the script to the same dir and rename it to autohotkey.ini

If someone starts yourfancyname.exe it will look for autohotkey.ini and run your script.

Zip exe + ini and send it to everyone who needs it tell them to unpack and run

Less chance of false positives with AV software as well

  • Guests
  • Last active:
  • Joined: —

How would that work when I send several routines (all different) to the same person?

I can’t see how you can have multiple .ini.files — unless my recipients put the routines into different directories.

If that is required — it become easier just to give them several .exe files.

(I tried turning off my anti-virus — I still got the error message )

  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

It is customary to have a folder per application, problem solved 🙂

Another option which is much easier: Simply have them install autohotkey (might not be possible if they don’t have the right to do so) but you could create a small launcher:

Yourapplication.exe
autohotkey.ini -> will simply create a menu of all *.ahk files in the same dir «which program do you want to start»
and you send them the scripts and tell them to place in the same folder as yourapplication and AutoHotkey.ini. Again no need to compile!

Do you run it as administrator + where you write you scripts to, c: for example is possibly not allowed when using vista (you can’t write to the root folder, perhaps there are others too)

  • Guests
  • Last active:
  • Joined: —

This all seems to be getting very complicated.

I will work through your suggestions to see how they would best work, but I thought that I had a simple question to overcome a problem in creating .exe files — they are the simplest way of distributing my routines :

Every time that I try to compile a .ahk script I get an error message in a message box :

Error: Error opening the destination file

  • Guests
  • Last active:
  • Joined: —

  • Members
  • 4999 posts
  • Last active:
  • Joined: 27 May 2007

This all seems to be getting very complicated.

  • Members
  • 644 posts
  • Last active: Jul 03 2013 08:08 PM
  • Joined: 12 May 2009

The only time I have seen the message ‘Error opening the destination file’ is when I am trying to compile a script but already have the previously compiled version running.

Make sure nothing to do with the script is running before you try to compile and see if that clears it up.

  • Guests
  • Last active:
  • Joined: —

I right-click on the .ahk file then click «compile».

Are you sure you are running as administrator + your AV is turned off?

  • Members
  • 1022 posts
  • Last active: Nov 27 2015 01:09 AM
  • Joined: 27 Apr 2008

Still no need to compile 😉

— Create a dir
— copy autohotkey.exe and rename yourfancyname.exe
— copy the script to the same dir and rename it to autohotkey.ini

If someone starts yourfancyname.exe it will look for autohotkey.ini and run your script.

Zip exe + ini and send it to everyone who needs it tell them to unpack and run

Less chance of false positives with AV software as well

It is customary to have a folder per application, problem solved 🙂

Another option which is much easier: Simply have them install autohotkey (might not be possible if they don’t have the right to do so) but you could create a small launcher:

Yourapplication.exe
autohotkey.ini -> will simply create a menu of all *.ahk files in the same dir «which program do you want to start»
and you send them the scripts and tell them to place in the same folder as yourapplication and AutoHotkey.ini. Again no need to compile!

Do you run it as administrator + where you write you scripts to, c: for example is possibly not allowed when using vista (you can’t write to the root folder, perhaps there are others too)

This all seems to be getting very complicated.

Really don’t compile it is a waste of time and effort. Are you sure you are running as administrator + your AV is turned off?

Or we can right click, click on compile and send them 1 file. Tell them to click on the 1 file. Seems easier to send one file.

Источник

Lexikos

From http://ahkscript.org/boards/viewtopic.php?f=14&t=9316

The following incorrectly produces an error:

FileInstall, test (1`,0).txt, test.txt

Error adding FileInstall file:
test (1`

Apparently it’s a known limitation — in ScriptParser.ahk there is a comment:

; TODO: implement `, detection

joedf

add /Mpress in Help, Label «BadParams» in Ahk2Exe.ahk

Msgbox, ... [/mpress 1 (true) | 0 (false)]...

? … i don’t know if it was intentional or forgotten… ;)

highend

Hi,

I’m compiling my .ahk scripts within Sublime Text 3 (with the help of a build script (a .bat file) that invokes ahk2exe with the necessary /in /out and /icon switch).

Is there any way to get the compiler (error) messages back into the console view of Sublime Text instead of getting a normal popup window? Regex parsing the output inside the console view allows to directly go to the line of an error for example.

Sublime Text 3 can be used as a portable application so if you’d like to take a look at it for yourself…

Tia,
Highend

joedf

On Exit, it should return an error «number» so the calling process can interpret the errors.
This is just an idea/suggestion.

HotKeyIt

cyruz-git

Hi fincs,
when you compile a script with an icon, the quality of the icon is consistently worse compared to the same icon in the uncompiled script set with the menu command.

I’m not sure this depends from Ahk2Exe, because from what I see in the code you just replace the main AHK icon with the custom one. Sorry if this is not pertinent.

Lexikos

Ahk2Exe (commit ae50d3a) is unable to compile itself or the following script:

MsgBox This line is not really FileInstall, but Ahk2Exe thinks it is. :(

Error: Invalid «FileInstall» syntax found. Note that the first parameter must not be specified using a continuation section.

Incidentally, it would be helpful if this error message indicated which file and line contains the supposed error.

Lexikos

#Include Dir fails to change the working directory if FileExist("Dir") would return anything other than «D», such as if the directory has the archive attribute set. The problem is in ScriptParser.ahk:

; bad
if FileExist(IncludeFile) = "D"

; good
if InStr(FileExist(IncludeFile), "D")

Getfree

In file ScriptParser.ahk line 68, the function FileExist is used to check whether the given path is a directory.
The proper way to do it should be to check whether the character «D» is present in the returned string, rather than testing for exact equality.
Sometimes the attribute string is something like «RD», «SD», etc..

Lexikos

In theory, the change in commit c7a7bc8 will not handle the Join option correctly. For example, (LTrim Join() would be treated as an expression by Ahk2Exe but not by AutoHotkey.

Schbatzafresser

I’m controlling an existing installation routine (covering 23 languages) with an AHK script which works fine. For deployment i would like to compile the script into an executable.
I’ve tried the ANSI, UNICODE32 and UNICODE64 setting but the window titles in greek, chinese, japanes, korean, russian, bulgarian are not catched any more.
When comparing the compiler output (which contains the script) with the script, some window titles captured with the window spy in the languages described are somehow changed.
e.g.: «Äîáðî ïîæàëîâàòü» (russian «welcome») is compiled to «Ã„îáðî ïîæàëîâàòü»

In detail:
; 0419 russisch
IfWinExist, Äîáðî ïîæàëîâàòü
{
WinActivate
Click 338, 339
}

compiled to

IfWinExist, Äîáðî ïîæàëîâàòü
{
WinActivate
Click 338, 339
}

Lexikos

The following causes an error message, as Ahk2Exe misinterprets it as an actual #include directive:

Source: Try compiling this…

Lexikos

During compilation with the latest commit, I get an error message about __temp.ahk. The following line is missing a second parameter (filename):

FileAppend, ExitApp `% (A_IsUnicode=1) << 8 | (A_PtrSize=8) << 9

Lexikos

Steps to reproduce: Attempt a command-line compile using the /bin switch, with no .bin files in the Ahk2Exe directory.

Expected result: Compile succeeds with no warnings.

Actual result: A warning is shown that Ahk2Exe is unable to copy the appropriate binary file. Compilation succeeds after dismissing the warning.

Background: My release script pulls in Ahk2Exe and compiles it by running Ahk2Exe.ahk on the command line. The most up-to-date .bin file is specified on the command line, as I have no need to copy the .bin files into the Ahk2Exe source directory.

If the bin file is specified on the command line or a non-default file is selected from the GUI, there should be no need to create AutoHotkeySC.bin. I’d suggest the check be performed in one of the following cases:

  • when «(Default)» is selected, or on startup (in GUI mode) if it was already selected. If the user has run it before and selected a different .bin, there’s no need to nag.
  • when the user attempts to compile with AutoHotkeySC.bin.

Lexikos

If AutoHotkey.exe is entirely absent, compilation is aborted and the following error message is shown:

Error: The AutoHotkey build used for auto-inclusion of library functions is not recognized.

Specifically: (Ahk2Exe directory)..AutoHotkey.exe

Either of the following would be preferable:

  • Warn the user that auto-inclusions won’t work because AutoHotkey.exe is absent, but continue anyway.
  • Just compile. (Preferred for command-line mode.)

Lexikos

The error message when the bin file doesn’t exist, while marginally more useful than before, is still unclear. It implicates the destination as a possible source of the error, which would lead the user in the wrong direction. Something like «Selected bin file does not exist» would be more accurate, clearer, and would lead to a solution more quickly.

However, I still think

the UI should use any available bin file, ask the user, or at least point out that the current selection («(Default)») is invalid.

I could ask users of the compiler download to rename their preferred file «AutoHotkeySC.bin», but it would be more intuitive for the compiler to just work in that situation. In particular, it doesn’t make sense to always provide the «(Default)» option if it’s not necessarily always valid.

Now that I think of it, the only reason to even have AutoHotkeySC.bin in the installation is for scripts that automate compilation which might expect it to exist. I think that includes Compile_AHK II. Edit: I was thinking the installer could simply write the bin file setting (based on the selected version) to the registry instead, but that mightn’t work since the setting is per-user.

Lexikos

In this thread, a user of AutoHotkey Basic had some problems compiling scripts for AutoHotkey_L using fincs’ Ahk2Exe. I believe the initially reported error message (invalid character in variable name) was caused by Ahk2Exe invoking AutoHotkey.exe /iLib, where AutoHotkey.exe is AutoHotkey Basic, and that the error ultimately didn’t prevent the compilation from succeeding.

My first thought was to simply suppress error messages by using /ErrorStdOut /iLib, but I’m not sure if this is appropriate since auto-includes may fail in that scenario, depending on whether AutoHotkey Basic can load the script. Can you think of a better solution?

If not, perhaps it would be sufficient for me to add a readme to the compiler download, documenting the specific requirements for auto-include support.

Lexikos

When I attempt to compile a script in the same directory as Ahk2Exe.exe, I get the following error:

Error: Error opening the destination file.

Moving the same script to the desktop and compiling it works.

Edit: The actual issue was that Ahk2Exe tries to use AutoHotkeySC.bin even if it doesn’t exist, and fails with an inappropriate error message.

Lexikos

The following includes Foo.ahk twice, when compiled:

The original Ahk2Exe writes the processed script text into a temporary file as it goes along, and passes this file to AutoHotkey.exe /iLib. Because the #Include line was stripped out before it got to AutoHotkey.exe, it didn’t add the lib file to its output. I implemented #Include <Lib> support in Ahk2Exe to resolve this, though I realize now that I could have simply written the original #Include line into the temporary file and let AutoHotkey.exe do the rest.

Since your script passes the original filename to AutoHotkey.exe /iLib, both it and your script process the #Include line. This causes the file to be included twice. I think the best solution is to simply ignore any instances of #Include <Lib> and let AutoHotkey.exe handle it. You can either pass the original filename as you do now, or pass a temporary file containing the processed text.

Lexikos

Quote marks should not be used here:

If AutoHotkey.exe isn’t present, there’s a possibility that an old _ilib.ahk file will be used.

autohotkey / ahk2exe
Goto Github
PK

View Code? Open in Web Editor
NEW

416.0
416.0
99.0
372 KB

Official AutoHotkey script compiler — written itself in AutoHotkey

Home Page: https://autohotkey.com/

License: Do What The F*ck You Want To Public License

AutoHotkey 100.00%

ahk2exe’s Issues

[ahk2exe directive] Add directive to set uac level

Please add directive to set uac level.

Compiled script doesn’t work with greek, chinese, japanes, korean, russian, bulgarian strings

I’m controlling an existing installation routine (covering 23 languages) with an AHK script which works fine. For deployment i would like to compile the script into an executable.
I’ve tried the ANSI, UNICODE32 and UNICODE64 setting but the window titles in greek, chinese, japanes, korean, russian, bulgarian are not catched any more.
When comparing the compiler output (which contains the script) with the script, some window titles captured with the window spy in the languages described are somehow changed.
e.g.: «Äîáðî ïîæàëîâàòü» (russian «welcome») is compiled to «Ã„îáðî ïîæàëîâàòü»

In detail:
; 0419 russisch
IfWinExist, Äîáðî ïîæàëîâàòü
{
WinActivate
Click 338, 339
}

compiled to

IfWinExist, Äîáðî ïîæàëîâàòü
{
WinActivate
Click 338, 339
}

Error message shown by /iLib is confusing

In this thread, a user of AutoHotkey Basic had some problems compiling scripts for AutoHotkey_L using fincs’ Ahk2Exe. I believe the initially reported error message (invalid character in variable name) was caused by Ahk2Exe invoking AutoHotkey.exe /iLib, where AutoHotkey.exe is AutoHotkey Basic, and that the error ultimately didn’t prevent the compilation from succeeding.

My first thought was to simply suppress error messages by using /ErrorStdOut /iLib, but I’m not sure if this is appropriate since auto-includes may fail in that scenario, depending on whether AutoHotkey Basic can load the script. Can you think of a better solution?

If not, perhaps it would be sufficient for me to add a readme to the compiler download, documenting the specific requirements for auto-include support.

ScriptParser.ahk

Unable to copy error by command line

I got an error when I tried to make exe by the command line:

"C:Program FilesAutoHotkeycompilerahk2exe.exe" /in my_script.ahk /out my_script.exe

Following message appeared on the popup:

Error: Unable to copy AutoHotkeySC binary file to destination.

Specifically:
"C:UsersuserAppDataLocalTemp~Ahk2Exe~buildmy_script~exe~511090884045458.tmp"

After I made ~Ahk2Exe~build folder directly, the command succeeded.

The error is shown from version 1.1.33.00.
Version 1.1.32.00 does not show the error (and it seems the temporary file is different like C:UsersuserAppDataLocalTemp~tempXXXXXXXX.tmp)

The error does not occur when I use GUI and execute convert even at version 1.1.33.00 and later.

Expression/continuation section detection flaw

In theory, the change in commit c7a7bc8 will not handle the Join option correctly. For example, (LTrim Join() would be treated as an expression by Ahk2Exe but not by AutoHotkey.

Add option to specify options to MPRESS

Mpress has a bunch of command line options. It would be nice to be able to specify them with the compiler, instead of compiling the scripts without compression and then manually running MPRESS.

This would be most useful in the UI, although it should also probably be available on the command line. Just add a text box after the Use MPRESS option that can contain MPRESS parameters.

Implement escape-comma support in FileInstall’s parameters

From http://ahkscript.org/boards/viewtopic.php?f=14&t=9316

The following incorrectly produces an error:

FileInstall, test (1`,0).txt, test.txt

Error adding FileInstall file:
test (1`

Apparently it’s a known limitation — in ScriptParser.ahk there is a comment:

; TODO: implement `, detection

#Include acts like #IncludeAgain

When compiled, the following script shows two message boxes. It should show only one.

; Main.ahk
#Include Include.ahk
#Include Include.ahk

; Include.ahk
MsgBox

Furthermore, attempting to compile the following script crashes the compiler:

; Self.ahk
#Include Self.ahk

The correct behaviour is to ignore #Include if the full path of the file matches the full path of a previously included file.

Detecting directory paths

In file ScriptParser.ahk line 68, the function FileExist is used to check whether the given path is a directory.
The proper way to do it should be to check whether the character «D» is present in the returned string, rather than testing for exact equality.
Sometimes the attribute string is something like «RD», «SD», etc..

Unicode32-bit.bin does not exist?

It says «Unable to copy the appropriate binary file as AutohotkeySC.bin because said file does not exist:
…………Unicode32-bit.bin

Do you still want to continue?»
How to fix this?

Edit: Ok, I’ve found out it is originally be placed at
%Program Files%AutoHotkeyCompilerAutoHotkeySC.bin

There has never been any «Compiler» folder. Maybe there was a problem during installation process.

[gui] Show list of ahk2exe directives

The gui should have a second «expert» tab to show the ahk2exe directives found in script file.

As additional improvement it would be great ifvthe user can edit the directives and save them in the script.

The directives could be shown as list or table.

EXAMPLE

Directive Properties
name1 values
name2 values

Could not extract script from EXE

nevermind

_lib.ahk is never deleted

Quote marks should not be used here:

If AutoHotkey.exe isn’t present, there’s a possibility that an old _ilib.ahk file will be used.

Can’t compile a script in the Ahk2Exe dir

When I attempt to compile a script in the same directory as Ahk2Exe.exe, I get the following error:

Error: Error opening the destination file.

Moving the same script to the desktop and compiling it works.

Edit: The actual issue was that Ahk2Exe tries to use AutoHotkeySC.bin even if it doesn’t exist, and fails with an inappropriate error message.

add /Mpress in Help, Label «BadParams» in Ahk2Exe.ahk

add /Mpress in Help, Label «BadParams» in Ahk2Exe.ahk

Msgbox, ... [/mpress 1 (true) | 0 (false)]...

? … i don’t know if it was intentional or forgotten… ;)

__temp.ahk doesn’t exist

During compilation with the latest commit, I get an error message about __temp.ahk. The following line is missing a second parameter (filename):

FileAppend, ExitApp `% (A_IsUnicode=1) << 8 | (A_PtrSize=8) << 9

scripts compiled by ahk2exe are being catched by AVG anti-virus.

I have used this software without any issues in past (I used to have the same anti-virus too). Now, when I compile the ahk script the AVG takes it as a threat and move it to quarantine.

AVG says: ‘Win-32:Evo-gen [Susp]’ threat level: medium

`#Include Dir` fails if Dir has other attributes

#Include Dir fails to change the working directory if FileExist("Dir") would return anything other than «D», such as if the directory has the archive attribute set. The problem is in ScriptParser.ahk:

; bad
if FileExist(IncludeFile) = "D"

; good
if InStr(FileExist(IncludeFile), "D")

Directive PostExec: add `Silent` and `Hidden`

I wonder if maybe a silent and/or hidden parameter should be added to the PostExec directive, like the Run[Wait] command.
Currently if I simply do the following, it works fine and no errors (RC = 0, return code?) are thrown:

;@Ahk2Exe-PostExec mpress.exe "%A_WorkFileName%", 0

… but if the executable is not found or returns a non-zero exit code, a error msgbox is shown. Since I simply want compression if it’s available, it’s okay if it fails. I do the following to allow it to fail silently.

; Trick to use mpress and throw no error if not available
;@Ahk2Exe-PostExec cmd /c mpress.exe "%A_WorkFileName%" &rem, 0

Perhaps, there are other use cases where this could useful?

;@Ahk2Exe-PostExec FailureIsOkay.exe "%A_WorkFileName%" , 0, 1, 1

Syntax being:

;@Ahk2Exe-PostExec Program [parameters] [, When, Hidden, Silent]

So no console (or whatever program) window flashes, and fails silently. What do you think?

Compile messages without GUI?

Hi,

I’m compiling my .ahk scripts within Sublime Text 3 (with the help of a build script (a .bat file) that invokes ahk2exe with the necessary /in /out and /icon switch).

Is there any way to get the compiler (error) messages back into the console view of Sublime Text instead of getting a normal popup window? Regex parsing the output inside the console view allows to directly go to the line of an error for example.

Sublime Text 3 can be used as a portable application so if you’d like to take a look at it for yourself…

Tia,
Highend

[Ahk2Exe-Edge]Directive SetVersion is not working in 32bit — Ansi version

Could you test compiling Ahk2Exe.ahk to Ahk2Exe.exe by using Ansi Version?
Directive SetVersion is not working in 32bit — Ansi version
szKey Value is not same as follows
Unicode Ver : VS_VERSION_INFO
Ansi ver : V
So occuring out of memory.
Error in #include VersionRes.ahk
Out of memory
026: while addr < addrLimit
027: {
028 : size := (NumGet(addr+0, «Ushort») + 3) &~3, blabla~~

 class VersionRes
 {
 Name := ""
 ,Data := ""
 ,IsText := true
 ,DataSize := 0
 ,Children := []
__New(addr := 0)
{
    if !addr
        return this
    wLength := NumGet(addr+0, "UShort"), addrLimit := addr + wLength, addr += 2
    ,wValueLength := NumGet(addr+0, "UShort"), addr += 2
    ,wType := NumGet(addr+0, "UShort"), addr += 2
    ;Need to modify below
            szKey := StrGet(addr), addr += 2*(StrLen(szKey)+1), addr := (addr+3)&~3

    ObjSetCapacity(this, "Data", size := wValueLength*(wType+1))
     ;Check Value is Correct


msgbox,% "wLength : " wLength " nwValueLength : " wValueLength " nszKey : " szKey "`nwType : " wType
 ;szKey Value is not Correct. as follows Unicode Ver : VS_VERSION_INFO , Ansi ver : V
 ;so occuring out of memory
    this.Name := szKey
    ,this.DataSize := wValueLength
    ,this.IsText := wType
    ,DllCall("msvcrtmemcpy", "ptr", this.GetDataAddr(), "ptr", addr, "ptr", size, "cdecl"), addr += size, addr := (addr+3)&~3
     ;if wType
    ;ObjSetCapacity(this, "Data", -1)
    while addr < addrLimit
    {
        size := (NumGet(addr+0, "UShort") + 3) & ~3
        ,this.Children.Insert(new VersionRes(addr))
        ,addr += size
    }
}

_NewEnum()
{
    return this.Children._NewEnum()
}

AddChild(node)
{
    this.Children.Insert(node)
}

GetChild(name)
{
    for k,v in this
        if v.Name = name
            return v
}

GetText()
{
    if this.IsText
        return this.Data
}

SetText(txt)
{
    this.Data := txt
    ,this.IsText := true
    ,this.DataSize := StrLen(txt)+1
}

GetDataAddr()
{
    return ObjGetAddress(this, "Data")
}

Save(addr)
{
    orgAddr := addr
    ,addr += 2
    ,NumPut(ds:=this.DataSize, addr+0, "UShort"), addr += 2
    ,NumPut(it:=this.IsText, addr+0, "UShort"), addr += 2
    ,addr += 2*StrPut(this.Name, addr+0, "UTF-16")
    ,addr := (addr+3)&~3
    ,realSize := ds*(it+1)
    ,DllCall("msvcrtmemcpy", "ptr", addr, "ptr", this.GetDataAddr(), "ptr", realSize, "cdecl"), addr += realSize
    ,addr := (addr+3)&~3
    for k,v in this
        addr += v.Save(addr)
    size := addr - orgAddr
    ,NumPut(size, orgAddr+0, "UShort")
    return size
}


}

;@Ahk2Exe-SetName Ahk2Exe
;@Ahk2Exe-SetDescription AutoHotkey Script Compiler
;@Ahk2Exe-SetCopyright Copyright (c) since 2004
;@Ahk2Exe-SetCompanyName AutoHotkey
;@Ahk2Exe-SetOrigFilename Ahk2Exe.ahk
;@Ahk2Exe-SetMainIcon Ahk2Exe.ico

;@Ahk2Exe-SetVersion 1.0.0.1

I had to check value is correct.
msgbox,% «wLength : » wLength » nwValueLength : » wValueLength » nszKey : » szKey «`nwType : » wType
szKey Value is not same as follows
Unicode Ver : VS_VERSION_INFO
Ansi ver : V
So occuring out of memory.
Error in #include VersionRes.ahk
Out of memory
026: while addr < addrLimit
027: {
028 : size := (NumGet(addr+0, «Ushort») + 3) &~3, blabla~~

I modify below and szKey Value is correct.
szKey := StrGet(addr,»UTF-16″)
and then Compilation is complete without out of memory.
Set Version is replaced correctly.
But, Set Description is not correct as follows. (Such as Text is not correct ; likes wType=1)
畁潴潈歴祥匠牣灩⁴潃灭汩牥䘀潲卭牴慥Ɑ摇灩畬屳摇灩牃慥@��FileVersion
This script is difficult to understand. I can’t fix it anymore
Can you do fix it?

Does it accept params?

To use with «Run», like source, destination, icon…

add Exit with Errorlevels

On Exit, it should return an error «number» so the calling process can interpret the errors.
This is just an idea/suggestion.

Compilation fails if AutoHotkey.exe is entirely absent

If AutoHotkey.exe is entirely absent, compilation is aborted and the following error message is shown:

Error: The AutoHotkey build used for auto-inclusion of library functions is not recognized.

Specifically: (Ahk2Exe directory)..AutoHotkey.exe

Either of the following would be preferable:

  • Warn the user that auto-inclusions won’t work because AutoHotkey.exe is absent, but continue anyway.
  • Just compile. (Preferred for command-line mode.)

Unclear error message when AutoHotkeySC.bin doesn’t exist

The error message when the bin file doesn’t exist, while marginally more useful than before, is still unclear. It implicates the destination as a possible source of the error, which would lead the user in the wrong direction. Something like «Selected bin file does not exist» would be more accurate, clearer, and would lead to a solution more quickly.

However, I still think

the UI should use any available bin file, ask the user, or at least point out that the current selection («(Default)») is invalid.

I could ask users of the compiler download to rename their preferred file «AutoHotkeySC.bin», but it would be more intuitive for the compiler to just work in that situation. In particular, it doesn’t make sense to always provide the «(Default)» option if it’s not necessarily always valid.

Now that I think of it, the only reason to even have AutoHotkeySC.bin in the installation is for scripts that automate compilation which might expect it to exist. I think that includes Compile_AHK II. Edit: I was thinking the installer could simply write the bin file setting (based on the selected version) to the registry instead, but that mightn’t work since the setting is per-user.

Request: Add command-line option /ScriptExists=Reload | Unload | Ask

NOTE: This request has been updated, for latest please see «Revised Request» below

[EDIT: Original Request (out-dated)]

Hi guys, I would like to suggest removing the warning message that appears when trying to (re)-compile a script that is currently running, and the related question whether the file should be Unloaded of Reloaded.

Change

In this situation, ahk2exe could instead simply always (Unload, compile, and then) Reload the script.

Rationale / Context

I have a main .ahk script and several supporting .ahk scripts that are #include(d) — these are compiled into my ahk.exe program which autoruns when I login (and so is always running).

I often make changes to the supporting .ahk scripts (e.g. one of which is the AHK-provided Hotstring Manager / self-appending script) and (unless I missed something) need to re-compile my main .ahk script in order for changes to be pulled through / tested (closing/re-opening the .exe is not sufficient). Sometimes (in frequent change periods) I could get the Unload/Reload prompt 20+ times, which became quite distracting/laborious.

In the end, I removed the in-use check from ahk2exe.ahk (and instead always ran the code to Reloaded the file after it had re-compiled) and re-compiled ahk2exe… Personally, I much prefer the silent-Reload behaviour and it makes updating (and re-compiling my .ahk scripts) much easier now — so I thought I would at least propose the change to you guys (to make globally) if you wanted to do this.

Hopefully the above is clear (and you agree it would be a good change), please let me know if you have any questions/comments.


PS1 — Hopefully this request is taken in the right way, but just in case it seems I am being negative of ahk2exe, please note that is not my intention at all!.. The ahk2exe tool is great, I simply wanted to share a change that has helped me quite a lot personally, so this could be considered for wider roll-out to wider users.

PS2 — I realise I may not need to re-compile the script after every change and I could just run the un-compiled .ahk script instead, however I sometimes found differences between how the scripts sometimes ran as .ahk files vs. .exe files (e.g. with Hotstrings.ahk, trying to append to the script if it’s an .exe will fail, etc).. Also, as the compiled .exe autoruns on load, this meant I was running v1.0 of the .exe and v1.0.1 (i.e. different code) in the .ahk simultaneously, which had unpredictable results… So opting to always re-compile the script, seemed like a reasonable way to overcome these nuances.

Icon quality in compiled script

Hi fincs,
when you compile a script with an icon, the quality of the icon is consistently worse compared to the same icon in the uncompiled script set with the menu command.

I’m not sure this depends from Ahk2Exe, because from what I see in the code you just replace the main AHK icon with the custom one. Sorry if this is not pertinent.

append «.exe» suggested — Ahk2Exe.ahk#L295

Beta test report 1.1.30.03_Beta_8

Is this the right place to leave a beta test report?

Just to say that I tested 1.1.30.03_Beta_8 to compile my app QAP and everything worked well. My AHK source file includes various Ahk2Exe directives:

;@Ahk2Exe-IgnoreBegin

;@Ahk2Exe-IgnoreEnd

;@Ahk2Exe-SetVersion 10.2.1
;@Ahk2Exe-SetName Quick Access Popup
;@Ahk2Exe-SetDescription Quick Access Popup (Windows freeware)
;@Ahk2Exe-SetOrigFilename QuickAccessPopup.exe
;@Ahk2Exe-SetCopyright (c) Jean Lalonde since 2013
;@Ahk2Exe-SetCompanyName Jean Lalonde

If this can help, is there anything I could test more specifically?

Thanks for taking the time to update this so useful tool. Nice job!

Error: #include Lib file can not be opened

The AHK main file runs properly (under a directory named ‘ahk’)
If includes a Lib in A_ScriptDir/Lib/ConNext.ahk with : #Include
This ConNext Lib files includes another file in the same Lib directory via #include Encrypt.ahk
When I compile it, it gives this error looking for the Lib Encrypt.ahk not in the A_ScriptDir/Lib directory but in A_ScriptDir in my case: file …/ahk/Encrypt.ahk can not be opened

msgbox, «#include 1»

The following causes an error message, as Ahk2Exe misinterprets it as an actual #include directive:

Source: Try compiling this…

[CLI] Make the CLI mode completely headless

Can you consider making the CLI mode completly headless (i.e. no MsgBox/warnings), maybe just output everything to stdout.
or maybe make a new switch (like /headless) to disable msgboxes and output warnings, errors, and even the status to stdout.

This allows anyone to automate the compilation without the use of an AHK script or something similar to detect the msgboxes

Add icon resource

@fincs
I have noticed that adding icon resource through compile directives is not currently supported.
In case this is because you are not sure how to do this through UpdateResource WinAPI function there is an article explaining this here: http://www.codeguru.com/cpp/w-p/win32/tutorials/article.php/c12873/Hacking-Icon-Resources.htm
Specifically:
«… In resources, icons are split into several RC_ICON resources and a RC_GROUP_ICON. A RC_ICON entry is basically the above ICON IMAGE. RC_GROUP_ICON contains the ICON HEADER and DIRECTORY ENTRIES with a single modification: The DWORD ImageOffset becomes WORD ResourceID.»

Thanks for the comment in code on how to handle bitmap resources. I would have never guest you have to remove the BMP header.

Suggstion: Option to compile as console application

How about a built-in option or directive to compile as console application?

Scripts and code:

lexikos: I have a request for an option: «Compile as console application.»I think the uses are fairly obvious, but can elaborate if you need me to.The following (somewhat rudimentary) script can be used (via Run if desired) to change the subsystem of the AutoHotkeySC.bin file before the script is compiled. Ideally it would be used to modify Compile_AHK’s temporary copy of the bin file rather than the original. Using it directly on a compiled script exe invalidates its checksum and prevents the script from working.
https://autohotkey.com/board/topic/21189-compile-ahk-ii-for-those-who-compile/page-20#entry316030

lexikos: You can use the script I posted [above] after compiling the script. If it doesn’t work with Unicode/x64, use AutoHotkeyA32.exe (just to run the script I posted).
https://www.autohotkey.com/boards/viewtopic.php?p=144491#p144491

Attempts to copy .bin when /bin is specified

Steps to reproduce: Attempt a command-line compile using the /bin switch, with no .bin files in the Ahk2Exe directory.

Expected result: Compile succeeds with no warnings.

Actual result: A warning is shown that Ahk2Exe is unable to copy the appropriate binary file. Compilation succeeds after dismissing the warning.

Background: My release script pulls in Ahk2Exe and compiles it by running Ahk2Exe.ahk on the command line. The most up-to-date .bin file is specified on the command line, as I have no need to copy the .bin files into the Ahk2Exe source directory.

If the bin file is specified on the command line or a non-default file is selected from the GUI, there should be no need to create AutoHotkeySC.bin. I’d suggest the check be performed in one of the following cases:

  • when «(Default)» is selected, or on startup (in GUI mode) if it was already selected. If the user has run it before and selected a different .bin, there’s no need to nag.
  • when the user attempts to compile with AutoHotkeySC.bin.

ScriptParser.ahk

In ScriptParser.ahk line 93
if tline ~= «^w+s+(:=|+=|-=|=|/=|//=|.=||=|&=|^=|>>=|<<=)»
should be:
if tline ~= «^w+s+(:=|+=|-=|
=|/=|//=|.=||=|&=|^=|>>=|<<=)»

EXE not deleted when compilation fails

When compilation fails, the original Ahk2Exe deletes the output file. This is probably the most sensible thing to do. Currently the Ahk2Exe script leaves behind the executable, probably in whatever state it was at the point of failure. An easy way to reproduce this is to attempt to compile the following:

Off-topic background information: I had been attempting to compile my main hotkey script as a test. My main hotkey script #includes WindowPad, which uses FileInstall. Since FileInstall source paths are relative to the main script file’s directory and WindowPad was in a different directory, it failed.

Cannot run Ahk2exe in parallel using Powershell threads because of `Util_TempFile()`

Powershell threads trying to run ahk2exe in the same time will sometimes encounter a lock file issue when getting a temporary file name from Util_TempFile(). This happens when 2 threads get the same name at the same time, resulting in failure of some of the threads in our build script.

ExeFileTmp := Util_TempFile()

A solution to this would be using a universally unique identifier (UUID) library for generating temporary file names.

Add /icon# options to replace the other 4 embedded icons.

Using Properties/Change Icon of a link to a compiled script I can see that there are 5 embedded icons.

  • The 1st is the default tray icon and is replaced using /icon option.
  • The 2nd is the one used to mark script files, but does not appear to be used for the tray icon.
  • The 3rd is used when the hotkeys are Suspended.
  • The 4th and 5th are used in place of the 1st and 3rd when Paused.

It would be useful if each of these could be replaced independently through additional switches. (ex. /icon1 for the 2nd, /icon2 for the 3rd, …)

Usage in readme.txt points to l.autohotkey.net

Compatibility issue with long continuation sections in AHKv2

Hello,

i’ve written a script to write a hex string copied from HxD to a file. That means i can copy a hex pattern from a .jpg file (for example) and paste it into a continuation section in my script. The script then writes every decimal equivalent of a hex number with WriteChar() to my file. But if i want to compile my script (i use AHK v2.0-a134-d3d43350 Unicode x64 and compile it with the current Ahk2Exe version) and there is a long continuation section, Ahk2Exe returns «Error: The script contains syntax errors. […] Continuation section too long.». When i use resource hacker to put my script into the AHK v2 Unicode x64 .bin file, it works perfectly.
What i’ve tried:

  • compile without compression
  • with mpress
  • with upx
  • with other AHKv2 versions
    But no success.

My script:

SetWorkingDir A_ScriptDir ; Ensures a consistent starting directory.

hxStr := "
(
89 50 4E 47 0D 0A 1A 0A 00 00 00 0D 49 48 44 52 00 00 03 ; ... lots more here
)"
f := FileOpen("new.jpg", "w")
writeHexToFile(f, hxStr)
f.Close()

return

writeHexToFile(file, hexString)
{
	hex := {}
	i := 0
	while i <= 255
	{
		j := Format("{:#x}", i)
		if (j = 0)
		{
			j := "00"
		}
		else if (j < 16)
		{
			j := StrReplace(j, "0x", "0")
		}
		else
		{
			j := StrReplace(j, "0x", "")
		}

		hex.%j% := i
		i++
	}

	if (SubStr(hexString, 3, 1) = " ") ; Mode 1
	{
		chars := StrSplit(hexString, " ")
		for _, char in chars
		{
			char := StrLower(char)
			file.WriteChar(hex.%char%)
		}
	}
	else ; Mode 2
	{
		i := 1
		while i < StrLen(hexString)
		{
			char := StrLower(SubStr(hexString, i, 2))
			file.WriteChar(hex.%char%)
			i += 2
		}
	}
	return
}

Is it possible to port Ahk2Exe to AHKv2? This compiler could work, but it renames the script and then the generated .exe is not able to find and start this script…

Best regards,
Nick768

Do not write to target directory until compilation is complete (successful)

I believe the current behaviour of writing directly to the target path before compilation is complete causes this problem:

Error opening the destination file in Dropbox Folder
http://ahkscript.org/boards/viewtopic.php?f=14&t=10118

Additionally, if compilation fails, any previously existing (even valid) file at the target path is deleted. This is obviously not ideal.

A simple solution would be to write the intermediate file to a temporary location and move the result to the target path only after compilation succeeds.

Gui not remember bin

After relaunch the gui doesn’t remember the last selected bin.

Note: I didn’t compiled a script before close.

Invalid FileInstall syntax false positive

Ahk2Exe (commit ae50d3a) is unable to compile itself or the following script:

MsgBox This line is not really FileInstall, but Ahk2Exe thinks it is. :(

Error: Invalid «FileInstall» syntax found. Note that the first parameter must not be specified using a continuation section.

Incidentally, it would be helpful if this error message indicated which file and line contains the supposed error.

add Compile as Console application?

This script by Lexikos, changes the «signature» whether the application will use
the Console or the Windows Subsystem, Like in Visual Studio: http://msdn.microsoft.com/en-us/library/fcc1zstk(v=vs.90).aspx

;"Compile as console application" Script by Lexikos
;from: http://www.autohotkey.com/board/topic/21189-compile-ahk-ii-for-those-who-compile/page-20#entry316030
;-------------------------------------------------------------------------------------

; Args:
;   1   filename of bin/exe file to switch
;   2   subsystem, i.e. "C" (console) or "G" (gui).  if omitted, switches between the two.
ifNotExist %1%
    ExitApp -1
file = %1%
if 2 not in ,C,G
    ExitApp -1

; Define Win32 constants.
GENERIC_READ  := 0x80000000
GENERIC_WRITE := 0x40000000
OPEN_EXISTING := 0x3
IMAGE_DOS_SIGNATURE := 0x5A4D
IMAGE_NT_SIGNATURE := 0x4550
IMAGE_SIZEOF_FILE_HEADER := 20
IMAGE_SUBSYSTEM_WINDOWS_GUI := 2
IMAGE_SUBSYSTEM_WINDOWS_CUI := 3

; Open file for read/write.
hfile := DllCall("CreateFile", "str", file, "uint", GENERIC_READ|GENERIC_WRITE, "uint", 0, "uint", 0, "uint", OPEN_EXISTING, "uint", 0, "uint", 0)
if hfile = -1
    ErrorExit("CreateFile failed")

; Verify EXE signature.
e_magic := SeekNumRead(hfile, 0, "ushort")
if (e_magic != IMAGE_DOS_SIGNATURE)
    ErrorExit("Bad exe file: no DOS sig")

; Get offset of IMAGE_NT_HEADERS.
e_lfanew := SeekNumRead(hfile, 60, "int")

; Verify NT signature.
ntSignature := SeekNumRead(hfile, e_lfanew, "uint")
if (ntSignature != IMAGE_NT_SIGNATURE)
    ErrorExit("Bad exe file: no NT sig")

; Calculate offset of IMAGE_OPTIONAL_HEADER and its Subsystem field.
offset_optional_header := e_lfanew + 4 + IMAGE_SIZEOF_FILE_HEADER
offset_Subsystem := offset_optional_header + 68

; Read current subsystem.
Subsystem := SeekNumRead(hfile, offset_Subsystem, "UShort")
; Toggle subsystem (do this even if it will be overridden, to validate):
if (Subsystem = IMAGE_SUBSYSTEM_WINDOWS_GUI)
    Subsystem := IMAGE_SUBSYSTEM_WINDOWS_CUI
else if (Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI)
    Subsystem := IMAGE_SUBSYSTEM_WINDOWS_GUI
else
    ErrorExit("Bad subsystem: " Subsystem)

; Allow override on command-line:
if 2 !=  ; i.e. it is C or G
    Subsystem := IMAGE_SUBSYSTEM_WINDOWS_%2%UI

; Write new subsystem.
SeekNumWrite(Subsystem, hfile, offset_Subsystem, "UShort")

DllCall("CloseHandle", "uint", hfile)

MsgBox Changed subsystem to %Subsystem%.


; SeekNumRead: Seek to absolute offset and read a number of the specified type.
SeekNumRead(hfile, offset, type) {
    Seek(hfile, offset)
    VarSetCapacity(v,8), bytesToRead := NumPut(0,v,0,type)-&v
    if !(DllCall("ReadFile", "uint", hfile, "uint", &v, "uint", bytesToRead, "uint*", bytesRead, "uint", 0) && bytesRead == bytesToRead)
        ErrorExit("Read failed")
    return NumGet(v,0,type)
}

; SeekNumWrite: Seek to absolute offset and write a number of the specified type.
SeekNumWrite(num, hfile, offset, type) {
    Seek(hfile, offset)
    VarSetCapacity(v,8), bytesToWrite := NumPut(num,v,0,type)-&v
    if !(DllCall("WriteFile", "uint", hfile, "uint", &v, "uint", bytesToWrite, "uint*", bytesWritten, "uint", 0) && bytesWritten == bytesToWrite)
        ErrorExit("Write failed")
}

Seek(hfile, offset) {
    static FILE_BEGIN := 0
    if DllCall("SetFilePointer", "uint", hfile, "int", offset, "uint", 0, "uint", FILE_BEGIN) = -1
        ErrorExit("Seek failed")
}

ErrorExit(msg) {
    MsgBox %msg%`n  ErrorLevel=%ErrorLevel% A_LastError=%A_LastError%
    global hfile
    if (hfile != "" && hfile != -1)
        DllCall("CloseHandle", "uint", hfile)
    ExitApp
}

Add more specificity to script syntax errors message.

Had a guy in the IRC today asking why he no longer got a specific error message when his script contains syntax errors. I pinpointed the change to commit 212f017 . I suggest passing the error message from /ErrorStdOut into the extra parameter of Util_Error.

#Include <Foo> includes twice

The following includes Foo.ahk twice, when compiled:

The original Ahk2Exe writes the processed script text into a temporary file as it goes along, and passes this file to AutoHotkey.exe /iLib. Because the #Include line was stripped out before it got to AutoHotkey.exe, it didn’t add the lib file to its output. I implemented #Include <Lib> support in Ahk2Exe to resolve this, though I realize now that I could have simply written the original #Include line into the temporary file and let AutoHotkey.exe do the rest.

Since your script passes the original filename to AutoHotkey.exe /iLib, both it and your script process the #Include line. This causes the file to be included twice. I think the best solution is to simply ignore any instances of #Include <Lib> and let AutoHotkey.exe handle it. You can either pass the original filename as you do now, or pass a temporary file containing the processed text.

[gui] Default values for bin and compress

The gui should have default values selected on first start.

Affected settings: bin, compress

@Ahk2Exe-AddResource

Понравилась статья? Поделить с друзьями:
  • Error opening terminal sipp
  • Error opening terminal screen xterm 256color
  • Error opening terminal rxvt unicode
  • Error opening terminal linux
  • Error opening streaming file paks win64 pc all opt starpak