Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invoking superf4 xkill from CMD #39

Open
kkuhle opened this issue Dec 17, 2019 · 10 comments
Open

Invoking superf4 xkill from CMD #39

kkuhle opened this issue Dec 17, 2019 · 10 comments

Comments

@kkuhle
Copy link

kkuhle commented Dec 17, 2019

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
Copy link
Owner

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
Copy link
Author

kkuhle commented Dec 17, 2019

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
Copy link
Owner

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
Copy link
Owner

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!

@kkuhle
Copy link
Author

kkuhle commented Apr 5, 2020 via email

@Synetech
Copy link

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

@kkuhle
Copy link
Author

kkuhle commented Jun 30, 2021

@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

  • I frequently have issues with Teams where I need to restart (keyboard shortcuts stop working), but there are other apps and this would be a neat addition.

@stefansundin
Copy link
Owner

@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
Copy link
Author

kkuhle commented Jul 2, 2021

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`"
  • cmd /c 'C:\Users\kevink\Downloads\install\xkill\xkill.exe invokes the new xkill you kindly created so quickly
  • clip copies the output
  • sleep 5 waits (I've realized this isn't necessary at all)
  • explorer.exe "`cmd /c powershell.exe get-clipboard`" starts the application that was placed into the clipboard earlier

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
Copy link

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

REM normal start
SuperF4.exe

REM xkill start
SuperF4.exe -xkill

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants