Why is AutoHotKey somehow causing a nightmare of error messages which attack me until I reboot the machine?

0

I have this in my test.ahk:

#§::
SetTitleMatchMode, 1
WinActivate,Testwindow goes here
return

It's supposed to let me press WinKey + § (the key to the left of the "1" on my keyboard) to instantly bring up the window which begins with "Testwindow goes here" (there is only one) on Windows 10. The window in question is a PHP CLI script, therefore using cmd.exe.

And it does. Once!

If you press it again, the system instead goes into "terror mode", where it will spit out multiple identical GUI error boxes like this, every few seconds, no matter what I do, making it impossible to continue using the computer:

---------------------------
cmd.exe - Application Error
---------------------------
The application was unable to start correctly (0xc0000142). Click OK to close the application. 
---------------------------
OK   
---------------------------

I've tried turned off the .ahk script, I've killed the window in question, shut down a bunch of other processes, etc. No matter what I do, it keeps attacking me with those nonsensical error messages until I reboot the computer. Which I've done a large number of times now while trying to debug this, which is an absolute PITA since I have to enter a long decryption password every single time. I'm not rebooting or trying anything related to this again until I can be sure that it's the right code!

What could be wrong with what I have? Why does it work once?

I must say that I find the AutoHotKey manual extremely confusing and cryptic, no matter which section. Everything I've ever had to do with AHK has resulted in countless hours of reading, searching, asking, etc., when it should've taken a few seconds of just looking in the right place in the manual and then instantly knowing what to do.

windows
windows-10
autohotkey
asked on Super User Jan 2, 2020 by Leonard

1 Answer

0

What could be wrong with what I have?

In theory, there should be nothing wrong with the code you have (as presented). This should bring up the appropriate window without issue every time.

Regarding the pop-up you're receiving, to be clear, this is an extremely generic Windows error.

General Troubleshooting Suggestions

At a guess, you are encountering something much more specific to your setup. Some ideas to consider:

  • Make certain AutoHotkey is up-to-date - If there is an issue (bug) with AutoHotkey itself, this may solve the problem.

  • Test from the Desktop - If you have a third-party application Window open, this can interfere with AutoHotkey scripts. Left-click your Desktop before testing.

  • Use the .ahk code presented by itself 1 - That is, if this is part of a larger script, there may be other parts of your .ahk script that are causing the issue.

  • Try a different hotkey 1 - It's conceivable § could be causing an issue, depending on the keyboard. There is also the potential issue that (somehow) Win + § is triggering another program or function.

  • Try a different PHP script 2 - A simple example script which (anecdotally) didn't cause the issue described is provided at the end of this answer.

  • Change the Window name/startup - Use something like start "Test" php script.php and look for e.g. Test with WinActivate. This is longshot, but...

  • Disable third-party software on your PC - Anti-virus programs or any number of programs that might run in the background could cause the error you're receiving, independent of AutoHotkey.


1 ex. alternative_test.ahk

#f4::
    SetTitleMatchMode , 1
    WinActivate , Administrator: C:\Windows\system32\cmd.exe
Return

2 ex. test.php

<?php
$x = 0;

echo "\n";
echo "This PHP program will loop 10 times or until 10 is entered at the prompt.\n";

while($x <= 10) {
    echo "\n";
    echo "Please enter a value from 1 to 10: \n";
    $handle = fopen ("php://stdin","r");
    $line = fgets($handle);
    if(trim($line) == '10'){
        echo "\n";
        echo "You entered 10. Aborting loop!\n";
        exit;
    }
    fclose($handle);
    echo "\n";
    if ($x == 10){
        echo "X value has reached 10. Finishing loop!\n";
    } else {
    echo "Thank you, continuing...\n";
    echo "\n";
    echo "The current loop number is: $x";
    echo "\n";
    }
    $x+=1;
}
?>
answered on Super User Jan 3, 2020 by Anaksunaman • edited Jan 3, 2020 by Anaksunaman

User contributions licensed under CC BY-SA 3.0