Compiled exe is killed after "RunWait"

Report problems with documented functionality
skaface
Posts: 8
Joined: 16 Jun 2020, 04:49

Compiled exe is killed after "RunWait"

Post by skaface » 29 Apr 2021, 05:35

I have the following (very simple script):

Code: Select all

try {
  RunWait, "%localappdata%\Learnpulse\Screenpresso\Screenpresso.exe", "%localappdata%\Learnpulse\Screenpresso\"
} catch e {
  MsgBox, An exception was thrown!`nSpecifically: %e%
}
MsgBox, Done
When I run the above script by double clicking on the *.ahk file, everything is working as expected.

However, when I compile the file to an *.exe and run it, the program (Screenpresso) is shown as expected but the msg box is never shown. Also the tray icon of the AHK exe does not disappear from alone but only disappears when I hover with the mouse over it.

It seems like the process of the AHK exe is somehow killed unexpectedly. I'm using RunWait in many of my scripts but never came across such behavior before 🤷‍♂️

I just updated to the latest AHK version v1.1.33.08 just to be sure...

gregster
Posts: 6281
Joined: 30 Sep 2013, 06:48

Re: Compiled exe is killed after "RunWait"

Post by gregster » 29 Apr 2021, 06:57

Might be a false positive by your anti-virus program. Check its logs!

skaface
Posts: 8
Joined: 16 Jun 2020, 04:49

Re: Compiled exe is killed after "RunWait"

Post by skaface » 10 May 2021, 00:49

gregster wrote:
29 Apr 2021, 06:57
Might be a false positive by your anti-virus program. Check its logs!
I have no additional AV software installed and just turned off the Windows 10 "Virus & Thread protection" completely for testing but the exe still behaves the same.
I also tried adding the exe to the Windows Defenders "Exclusions" which did not help either.

Any idea where I might also look? Not sure if Windows 10 comes with even more built in protection apps that I'm not aware of 🤷‍♂️

gregster
Posts: 6281
Joined: 30 Sep 2013, 06:48

Re: Compiled exe is killed after "RunWait"

Post by gregster » 10 May 2021, 01:42

skaface wrote:
10 May 2021, 00:49
Any idea where I might also look? Not sure if Windows 10 comes with even more built in protection apps that I'm not aware of 🤷‍♂️
Not that I know of, but I rarely run compiled ahk scripts and usually don't have AV problems.

I can't reproduce the problem (but I used some other program) - if I understand correctly, this behaviour is - so far - exclusive to Screenpresso.exe and doesn't occur with other programs?

Not sure why it should only affect the exe version or if it changes anything in this specific case, but I think you shouldn't put the working directory (second parameter) between quotes - not finding the working directory can cause problems (but won't throw an error) - albeit usually for the ran program, afaik.
https://www.autohotkey.com/docs/commands/Run.htm#Parameters wrote:WorkingDir

The working directory for the launched item. Do not enclose the name in double quotes even if it contains spaces. If omitted, the script's own working directory (A_WorkingDir) will be used.
To be sure, I would also try the workingdir without the final \ which you included above.
The quotes in the first parameter shouldn't be necessary in this case either (but probably not a problem).

btw, did you run the exe from the same directory like you did with the uncompressed script ?

Others might have more ideas...

skaface
Posts: 8
Joined: 16 Jun 2020, 04:49

Re: Compiled exe is killed after "RunWait"

Post by skaface » 08 Jun 2021, 07:41

Hi gregster,

Yes, this only happens with the program Screenpresso.exe. I have many other compiled scripts starting other programs using RunWait but I've never seen such behavior before 🤷‍♂️

I adapted my script to your recommendations (remove " and leading \ from RunWait call) but that didn't change anything.
The compiled exe is still crashing whilst the ahk is still working.

I also removed the try/catch for simplicity as it wasn't working anyway.
Here's my current script:

Code: Select all

; Paste current image from clipboard into Screenpresso workspace and open editor
RunWait, %localappdata%\Learnpulse\Screenpresso\Screenpresso.exe, %localappdata%\Learnpulse\Screenpresso
Send {Ctrl Down}v{Ctrl Up}
Send {Enter}
Thanks again for your input and sorry for the long delay in my reply. I just didn't get around testing the things you mentioned earlier...

I still appreciate any input on this but I can also live with running the ahk instead of an compiled exe for this specific script for now 🤷‍♂️

lexikos
Posts: 7518
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: Compiled exe is killed after "RunWait"

Post by lexikos » 11 Jun 2021, 21:00

When the script "crashes", is there a corresponding error in the Application event log (which can be viewed with the system program, Event Viewer)?

User avatar
haichen
Posts: 596
Joined: 09 Feb 2014, 08:24

Re: Compiled exe is killed after "RunWait"

Post by haichen » 12 Jun 2021, 09:04

I have tried it a few times.
Most of the time the code works as a script as well as an exe.
Sometimes, however, the script (exe or ahk) is not terminated.
If I then close Screenpresso, the script is terminated regularly.

skaface
Posts: 8
Joined: 16 Jun 2020, 04:49

Re: Compiled exe is killed after "RunWait"

Post by skaface » 15 Jun 2021, 07:51

lexikos wrote:
11 Jun 2021, 21:00
When the script "crashes", is there a corresponding error in the Application event log (which can be viewed with the system program, Event Viewer)?
I just looked under Event Viewer -> Windows Logs -> Application and found nothing. Also there's no new entry when I run the exe which is then terminated 🤷‍♂️
Is there some other place I could look for such logs?

swagfag
Posts: 4498
Joined: 11 Jan 2017, 17:59

Re: Compiled exe is killed after "RunWait"

Post by swagfag » 19 Jun 2021, 11:31

skaface wrote:
15 Jun 2021, 07:51
Is there some other place I could look for such logs?
Incorrect use of this tool can degrade system performance or prevent Windows from starting, requiring you to reinstall Windows.
i suggest a system restore point
  • download Debugging Tools for Windows 10 https://docs.microsoft.com/en-us/window ... -10-windbg
  • run gflags, setup process exit monitoring for ur exe
    image.png
    image.png (29.07 KiB) Viewed 151 times
  • run ur exe
  • cause something to observe a "crash"
  • check the exit reason in Event Viewer > Windows Logs > Application Logs

fwiw, i cant reproduce the crash with a default installation of Screenpresso and v1.1.33.08, compiled with the provided compiler as A32/U32/U64:

Code: Select all

try {
  RunWait, "%localappdata%\Learnpulse\Screenpresso\Screenpresso.exe", "%localappdata%\Learnpulse\Screenpresso\"
} catch e {
  MsgBox, An exception was thrown!`nSpecifically: %e%
}
MsgBox, Done
running the compiled script launches Screenpresso and blocks on RunWait. then i kill Screenpresso(the way doesnt matter, graceful exit, taskkill, etc), which causes the ahk script to resume and trigger a "Done" msgbox
so this has nothing to do with ahk or Screenpresso.

skaface
Posts: 8
Joined: 16 Jun 2020, 04:49

Re: Compiled exe is killed after "RunWait"

Post by skaface » 21 Jun 2021, 09:06

swagfag wrote:
19 Jun 2021, 11:31
...
Interesting, I didn't know of that tool. Thank you very much for pointing this out 👍

I now see the following log in Event Viewer:
The process 'C:\Data\dev\WinScripts\AHK\Screenpresso\Screenpresso Open Editor With Clipboard.exe' was terminated by the process 'C:\Users\mike\AppData\Local\Learnpulse\Screenpresso\Screenpresso.exe' with termination code -1. The creation time for the exiting process was 0x01d766a4e9e5012d.
It seems that Screenpresso is somehow killing my exe which calls Screenpresso. Whilst definitely interesting, this isn't really helping me any further as I have no idea what to do with it 🤷‍♂️
So the status is still the same:

I'm ok with running the *.ahk instead of the *.exe but I'm still curious & appreciate every further help!


Here's the whole log just for completeness:
Log Name: Application
Source: Microsoft-Windows-ProcessExitMonitor
Date: 21.06.2021 15:54:15
Event ID: 3001
Task Category: None
Level: Information
Keywords: Classic
User: mike
Computer: MIKENB
Description:
The process 'C:\Data\dev\WinScripts\AHK\Screenpresso\Screenpresso Open Editor With Clipboard.exe' was terminated by the process 'C:\Users\mike\AppData\Local\Learnpulse\Screenpresso\Screenpresso.exe' with termination code -1. The creation time for the exiting process was 0x01d766a4e9e5012d.
Event Xml:
<Event xmlns="http schemas.microsoft.com /win/2004/08/events/event"> Broken Link for safety
<System>
<Provider Name="Microsoft-Windows-ProcessExitMonitor" Guid="{FD771D53-8492-4057-8E35-8C02813AF49B}" EventSourceName="Process Exit Monitor" />
<EventID Qualifiers="16384">3001</EventID>
<Version>0</Version>
<Level>4</Level>
<Task>0</Task>
<Opcode>0</Opcode>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2021-06-21T13:54:15.3557422Z" />
<EventRecordID>56755</EventRecordID>
<Correlation />
<Execution ProcessID="0" ThreadID="0" />
<Channel>Application</Channel>
<Computer>MIKENB</Computer>
<Security UserID="..." />
</System>
<EventData Name="EVENT_PROCESSTERMINATION_CROSSPROCESS">
<Data Name="param1">C:\Data\dev\WinScripts\AHK\Screenpresso\Screenpresso Open Editor With Clipboard.exe</Data>
<Data Name="param2">C:\Users\mike\AppData\Local\Learnpulse\Screenpresso\Screenpresso.exe</Data>
<Data Name="param3">-1</Data>
<Data Name="param4">01d766a4e9e5012d</Data>
</EventData>
</Event>

swagfag
Posts: 4498
Joined: 11 Jan 2017, 17:59

Re: Compiled exe is killed after "RunWait"

Post by swagfag » 21 Jun 2021, 09:55

what would happen if u renamed Screenpresso Open Editor With Clipboard.exe to not include the word "Screenpresso"?

skaface
Posts: 8
Joined: 16 Jun 2020, 04:49

Re: Compiled exe is killed after "RunWait"

Post by skaface » 22 Jun 2021, 00:17

swagfag wrote:
21 Jun 2021, 09:55
what would happen if u renamed Screenpresso Open Editor With Clipboard.exe to not include the word "Screenpresso"?
Haha, that was it! I guess they're ensuring that only 1 instance of the application is running by simply killing all "other" processes with "Screenpresso" in its name.
Thank you very much for pointing out the windows debug tools and suggesting the rename!

Post Reply

Return to “Bug Reports”