1

Basically the question is what is the Windows equivalent to Linux' changing tty, login in and killing processes from there?

Situation: Once in a while I switch back to Windows to play games when there seems no reasonable way to get them running under Linux. Problem is, that some of these games tend to crash frequently (screen freeze). However, when I try to open the task manager, I will get a black screen or simply cannot get out of the game, requiring me to restart my computer. Being a while into Linux, were you are usually not required to restart just because of unimportant applications, I figured that Windows might have considered the problem, too. Might be I want to run another important application in background that should not stop during playtime.

tl;dr How to kill processes in windows, or interact with the commandline when it's not possible to switch to Task Manager rsp. Alt-Tab to any other window, including commandline and PowerShell via offline solutions that require no additional applications?

Edit: What I already tried, but did not work ingame:

Try go get to cmd/taskmanager:

  • Ctrl+Alt+Del <-- proves that the machine is still responsive as it does switch to the menu where I can select task manager, but once I click I just get a task bar with black windows above or the frozen game screen, but no working window...

  • Ctrl+Shift+Esc

  • Win+x

  • Win+r

Try to exit application:

  • Alt+F4

  • press red X-button at right corner (not responsive when frozen)

Try to switch to other windows:

  • Alt+Tab

Open new virtual desktop:

  • Win+Tab
  • Ctrl+Win+Tab

It seems, Windows key bindings are context-sensitive. Any other options how to force quit an unresponsive application?

What would (probably) work:

  • Switch user via Ctrl+Alt+Del (but it seems excessive to create another user just for the purpose of killing a process)
  • sign out, sign in (but this also closes applications that should still be responsive, which is what I want to avoid, but at least better than a full restart)

I figured that until now, the following seems to work (the latter is not always available, but the former seems to work reliably up to now):

  • Task Manager -> Options > Always on Top
  • I created a shortcut for C:\Windows\System32\taskkill.exe /f /fi "status eq not responding" which I pinned to taskbar

However, this does not seem to scale well, what if I need more than just close a process via Task Manager or call another command, e.g. not kill all processes that do not respond but just one specific for which I yet have to figure out the PID?

kaiya
  • 123
  • 9
  • There don’t anything more than ending (or closing) a process in Windows. – Ramhound Sep 01 '21 at 12:48
  • Your post is pretty comprehensive, but your question is unclear. Do you mean that you want to kill one not responding process, among perhaps other not responding processes, but a process which you cannot identify? – harrymc Sep 01 '21 at 12:53
  • [How do I kill a program that hung with an always-on-top fullscreen window?](https://devblogs.microsoft.com/oldnewthing/20170425-00/?p=96035), [Terminate program that has taken over the screen](https://superuser.com/a/1542925/241386) – phuclv Sep 01 '21 at 15:44
  • @harrymc the question is whether there is an equivalent to Linux' tty-changing. As noted before, most methods either do not work at all, or are excessive. From all mentioned methods, only the Task Manager always on Top worked reliable until now (but is a nuissance when you forget to quit Task Manager and enter fullscreen). I am not happy with the solutions and I feel highly restricted. What, if I wanted to start a debugger without killing the process before? I am searching for a more superuser/root-like way to handle this situation, not the end-user clicky-shitty ways. – kaiya Sep 02 '21 at 14:50
  • Also, I am looking for a highly-reliable solution. I am not sure what I should do if Task Manager would fail once, too (had Task manager freezes in older Windows versions, so I don't like the idea of having a single point of failure at the moment). So basically, I am looking for the most compatible solution there is, even it is way longer, as long as it is fully reliable in all cases where there still is a reactive OS in the background. – kaiya Sep 02 '21 at 14:53

2 Answers2

1

Use Powershell. Start it as Administrator, then use Get-Process in combination with Stop-Process to list and stop processes/tasks. To list the tasks/processes:

Get-Process

To list the processes that are not responding:

Get-Process | Where { !$_.Responding }

To stop non-responding tasks:

Get-Process | Where { !$_.Responding } | Stop-Process -Force

To stop tasks based on task ID, first get the processes. Note the ID of the process you want to stop, then run the Stop-Process cmdlet. Replace IDofProcess with the process ID

Get-Process
Stop-Process -PID IDofPRocess -Force
Reddy Lutonadio
  • 17,120
  • 4
  • 14
  • 35
  • the problem is not the commands itself but rather the issue with not being able to get programs that aid killing frozen processes to the foreground, so I am seaking for (multiple) solutions how to deal with application freezes that prevent normal commandline usage ;-) – kaiya Sep 01 '21 at 13:21
  • But anyway, thanks ;-) – kaiya Sep 01 '21 at 13:21
1

You can use the free AutoHotkey.

The following script will kill the process owning the active window when pressing Ctrl+Alt+K:

^!k::                                         ; Ctrl+Alt+K
WinGet, PID, PID, % "ahk_id " WinExist("A")   ; Get process owning active window
Process, Close, %PID%                         ; Close this process

After installing AutoHotKey, put the script in a .ahk file and double-click it to test. You may stop the script by right-click on the green H icon in the traybar and choosing Exit. To have it run on login, place it in the Startup group at C:\Users\USER-NAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup.

Useful AutoHotkey documentation:

harrymc
  • 455,459
  • 31
  • 526
  • 924
  • Note: It's not advised to use it when the desktop has the focus (although it will restart itself automatically). – harrymc Sep 02 '21 at 15:09
  • I don't wish to install proprietary software for the sake of killing a process/accessing the cmd (they don't even provide a hash to check integrity :/), is there really no suitable Windows functionality to solve this properly? – kaiya Sep 02 '21 at 16:08
  • thanks for stating out it's open source, but mind https://securityintelligence.com/news/malware-using-autohotkey-scripts/ – kaiya Sep 02 '21 at 16:14
  • We seem to have cross-commented. My link for AutoHotKey source on [Github](https://github.com/Lexikos/AutoHotkey_L) was wrong. Note that a malware that uses AutoHotKey can just as well use PowerShell, so there's no difference. It's best not to get infected in the first place. – harrymc Sep 02 '21 at 16:18
  • Sure, but now consider I am working on a machine that is always offline and for which, security-wise, it is not allowed to install software. So I am seeking for a solution that can be used without any additional security implications. ;) – kaiya Sep 02 '21 at 16:19
  • You're playing games on an ultra-secure computer? – harrymc Sep 02 '21 at 16:30
  • No, the gaming situation raised the question, but I would prefer learning a way to achieve this which I can use in any case, because I tend to go for generic and scalable solutions. – kaiya Sep 02 '21 at 16:47
  • You could use AutoHotKey Portable, to carry it around with your scripts, and no virus could find it. – harrymc Sep 02 '21 at 17:48
  • On security-hardened machines are ports, including those of USB, usually deactivated, also, it does not seem to be scalable if I need to carry something with me ;) – kaiya Sep 03 '21 at 10:13