Prevent Alt+F4 from closing a specific program


  1. Posts : 68
    Windows 10
       #1

    Prevent Alt+F4 from closing a specific program


    I have a program (program 1) that goes dormant (not sure exactly what it is doing) when you run another program (program 2) from it (i.e. you go into program 1 and hit a button and program 2 launches, sending program 1 to the background). When you exit program 2, it brings program 1 out of dormancy. I am trying to use alt+F4 on a regular basis to close program 2 and bring program 1 back (this is from a controller). This used to work, but now hitting alt+F4 closes out program 1 first for some reason.

    Is there a way to make a program (in this case my program 1) "immune" to alt+F4?

    I never have any reason to use alt+F4 on this particular program, so I have no problem specifying somewhere "from this day forth, program 1 will never be alt+F4'ed!"
      My Computer


  2. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    You could achieve that with freeware Autohotkey, a well-documented scripting language.

    As a minimum, 1 line can redefine a key function.

    In your case, it would have to do a bit more, and test which program/process/window is in focus - which is easy enough.

    Autohotkey can:
    - modify key functions
    - manipulate existing windows and processes
    - even be used to create entire new programs

    Scripts can be typed and run directly as text files or compiled with 1 click to produce an exe file.

    Extract from help file:
    Prevent Alt+F4 from closing a specific program-1.jpg

    In your case you'd need to start with

    Alt & F4::

    I believe.

    It's very quick to produce a tiny script and try it, then build on it.

    Beginner Tutorial | AutoHotkey

    Quick Reference | AutoHotkey
      My Computers


  3. Posts : 68
    Windows 10
    Thread Starter
       #3

    dalchina said:
    In your case you'd need to start withAlt & F4::I believe.It's very quick to produce a tiny script and try it, then build on it.
    So, I found out a software I am already running for a different purpose allows me to run a batch file with a defined hotkey press. I'd like to stick with this instead of using AutoHotKey since it's already up and running all the time anyway, so I just need a batch file that does the following (paraphrasing code below). I'm not sure how I would right the parts to identify the active window and decide whether to kill it:

    @echo off

    Omit_List = ["program1.exe","program2.exe",...]
    Active_Program = <find active program window>

    if "Active_Program is listed in Omit_List"
    return
    else
    killtask /im Active_Program /F /T
    end
      My Computer


  4. Posts : 43,010
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #4

    Thank you for your reply. Good luck..
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 14:59.
Find Us




Windows 10 Forums