stefansundin / superf4

:file_folder: Kill programs instantly with Ctrl+Alt+F4. (Windows)
https://stefansundin.github.io/superf4/
GNU General Public License v3.0
660 stars 39 forks source link

Invoking superf4 xkill from CMD #39

Open kkuhle opened 4 years ago

kkuhle commented 4 years ago

It would be super neat to invoke SuperF4 from CMD. This would allow adding an alias for the command to the windows command in WSL bash environment and make me feel more like I am using Linux.

stefansundin commented 4 years ago

You mean like killall in Linux? Not a bad idea, but it would probably be a totally separate program.

In the mean time, maybe you can create a bat file named killall.bat that runs taskkill /IM "%1" /F, as described here: https://tweaks.com/windows/39559/kill-processes-from-command-prompt/

kkuhle commented 4 years ago

That's a good idea. I will have to set that up.

What I mean is in Linux, if you run "xkill" it reacts the same way as superf4 when you right-click > click xkill.

image

I would get a larger skull/cross appear if I was in a native Linux environment similar to superf4 where I can just click on an application to invoke killall on that application.

If it wouldn't be feasible in this application, I understand. I just thought it would be neat.

stefansundin commented 4 years ago

Oh. You are correct. I haven't used the xkill command in many years, but now that you mention it, that's why I named it xkill in SuperF4. :D

Yes, we should totally add that ability to SuperF4.. Or maybe I'll just rip out the xkill functionality into its own mini program.

stefansundin commented 4 years ago

Okay.. some months have passed, and today I finally gave this a try. I made a separate program, xkill.exe, that is basically the xkill functionality from SuperF4, but activated when the program is started and exits immediately after killing a program or when cancelled.

Differences from xkill in SuperF4:

Let me know what you think!

kkuhle commented 4 years ago

Yes!!! This is exactly what I was looking for!

Here is a video demonstrating how I pictured using this application:

https://drive.google.com/uc?id=1X0jAoNXHH79x5-8JXV6tnaFwwqAyLBcJ

And now I finally can. Thank you!!!

-Kevin

On Sat, Apr 4, 2020 at 9:31 PM Stefan Sundin notifications@github.com wrote:

Okay.. some months have passed, and today I finally gave this a try. I made a separate program, xkill.exe, that is basically the xkill functionality from SuperF4, but activated when the program is started and exits immediately after killing a program or when cancelled.

Differences from xkill in SuperF4:

  • Can't use the Escape key to cancel. Use the right or middle mouse buttons.
  • It does not use any keyboard or mouse hooks. I wanted to make an attempt without hooks first, the code is less complicated and it seems to work ok. If you cancel with the right mouse button, the window you had focused will lose focus for a moment as a result of this.

Let me know what you think!

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/stefansundin/superf4/issues/39#issuecomment-609236185, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACV242RPKHPHI5BZPZ5IUILRK73RPANCNFSM4J3VMS6Q .

Synetech commented 3 years ago

What's wrong with Windows' built-in taskkill?

kkuhle commented 3 years ago

@Synetech taskkill is fine, but I don't think we can use it to give us the neat skull to click on the desired process to kill.

@stefansundin is there any location that stores the application that gets killed? I'd like to add to my xkill alias by reloading some programs that I kill by using a different alias like rkill or something.

This is what I do currently:

alias xkill

alias xkill='/mnt/c/Users/kevin/gdrive/gapps/xkill/xkill.exe'

rkill would be something like

alias rkill

alias rkill='/mnt/c/Users/kevin/gdrive/gapps/xkill/xkill.exe ; sleep 5 ; cmd /c start /b "" "cmd /c start /b "" "C:\Users\kevink\AppData\Local\Microsoft\Teams\current\Teams.exe""'

C:\Users\kevink\AppData\Local\Microsoft\Teams\current\Teams.exe would ideally be replaced with the application I killed with superf4 xkill

stefansundin commented 3 years ago

@kkuhle

It's an interesting idea. I took a stab at it.

This new version outputs the path to the process that is about to be killed. This requires that a console window is used, so this new version may not be ideal if you launch it in other ways. So if you launch xkill.exe and then kill notepad then you will see the following:

C:\Windows\System32\notepad.exe

I wrote this .bat file which captures the output and launches it similar to what you were doing.

for /F "tokens=*" %%F in (' "xkill.exe" ') do (
  if errorlevel 0 cmd /c start /b "" "%%F"
)

The program now exits with error code 1 if you aborted the killing with the right mouse button (or if the TerminateProcess call failed for some reason). And there is no need for the sleep 5 part now that xkill will block until you are done with it. I'm not sure exactly what environment you are running it in (Cygwin?), so your mileage may vary.

Alternatively, it may be better to just have xkill launch the program instead. That way there isn't a need for the console window.

Anyway, have fun with it and let me know how it works.

kkuhle commented 3 years ago

That was much faster than expected and very appreciated! So this allows me to do exactly as was envisioning. Here is the command I am using that I will probably put into an rkill alias:

cmd /c 'C:\Users\kevink\Downloads\install\xkill\xkill.exe' | clip ; sleep 5 ; explorer.exe "`cmd /c powershell.exe get-clipboard`"

and here it is with a few example programs:

rkill_converted

I use wsl2 which is similar to Cygwin and IMO the best way to have a decent Linux env in Windows until Windows Subsystem for Linux came along a few years ago.

So I think what works best is to simply use this (omitting the sleep):

cmd /c 'C:\Users\kevink\Downloads\install\xkill\xkill.exe' | clip ; explorer.exe "`cmd /c powershell.exe get-clipboard`"

It might be nice for folks (in case this isn't too niche and others would want to do it) like you said:

Alternatively, it may be better to just have xkill launch the program instead.

Either way, this is good enough for me. Thank you so much!

eadmaster commented 11 months ago

why not simply adding a cmdline arg to the existing exe? e.g.

REM normal start
SuperF4.exe

REM xkill start
SuperF4.exe -xkill