Search code examples
windowsbatch-filecmdautohotkeytaskkill

batch script to kill last application


I would like to create a batch script, which when launched by a keyboard shortcut, will use taskkill /f /im to force quit the last application I was on.

I think that this could probably work by getting the last app's name as a variable, and then killing it (that variable), but I'm unfamiliar with batch, and don't know how applications/processes work in Windows. Any help would be greatly appreciated.

I've tried using the following script, which I got from here, but unfortunately that didn't work.

Pause::
WinGet,win_pid,PID,A
Run,taskkill /f /pid %win_pid%,,,
return

Solution

  • Using AutoHotKey

    You need to install autoHotKey in order to use this script.

    You can download it @ https://www.autohotkey.com/

    After you download and install it, have a look at the documentation.

    I think you should go through the first 3 sections since it will be beneficial for you to understand:

    • how scripts work
    • how to edit them
    • how to run them

    It's really a 5 minute read.