Page 1 of 1

Unable to taskill some cmd.exe instances

Posted: 02 Aug 2022 09:23
by DOSadnie
Long story short: by a mistake a created a BAT file with a looped execution of itself. This resulted in multiple CMD icons appearing extremely fast on and disappearing from my Taskbar


So instead of just resetting the system I went to

Task Manger > Process

and closed Windows Command Processor. But it did not work, as it instantly was right back. So I quickly wrote this

Code: Select all

taskkill cmd.exe /F
script and then very quickly executed it multiple times with a left mouse button clicks of BAT file holding it. And it worked, i.e. the Taskbar was clear of CMD icons and Task Manger was also showing no signs of Command Prompt


So then I wanted to be sure that this BAT will work always. So I executed

C:\Windows\system32\cmd.exe

both normally and As Administrator and once again executed my newest BAT. And [surprise] it did not work. So I went to

Task Manger > Details > cmd.exe > [RIGHT CLICK] End Task

and [surprise, surprise] it also did not work. But when I tried

Task Manger > Details > cmd.exe > [RIGHT CLICK] End Process Tree

it did work. The same case was with the other cmd.exe instance. And so I went back to my BAT and reworked it to

Code: Select all

taskkill /F /IM /T cmd.exe
but [surprise, surprise, surprise] it did not work


I also repeated some time later my test- and to my [this time real] surprise End Task in Task Manger was able to close without a sweat all of my cmd.exe instances. But nevertheless that BAT file still was not able to do so



So how can I 100% taskkill every instance of cmd.exe - or - is there an alternative command for BAT scripts for closing of programs? Or maybe some PS1 script could take care of this issue? [A PowerShell script could be even better as it could execute taskkill or similar command multiple time, with some time delays in-between]



I am using Windows 10 Enterprise 20H2 19042.746 x64

Re: Unable to taskill some cmd.exe instances

Posted: 02 Aug 2022 10:14
by aGerman
DOSadnie wrote:
02 Aug 2022 09:23
taskkill /F /IM /T cmd.exe
I guess you just messed with the arguments. /IM is for image name and apparently cmd.exe is the imagename. Thus, it must follow after /IM rather than after /T.

Steffen

Re: Unable to taskill some cmd.exe instances

Posted: 02 Aug 2022 15:04
by ShadowThief
Take a look at the output of taskkill /?

Code: Select all

TASKKILL [/S system [/U username [/P [password]]]]
         { [/FI filter] [/PID processid | /IM imagename] } [/T] [/F]
/IM must be immediately followed by the imagename, and /T is separate from it

Re: Unable to taskill some cmd.exe instances

Posted: 03 Aug 2022 13:14
by DOSadnie
ShadowThief wrote:
02 Aug 2022 15:04
Take a look at the output of taskkill /?
[...]
I had. But being molto stupido that I am, I then ignored everything other than that nicely spaced list of parameters


So this works

Code: Select all

taskkill /IM cmd.exe /T /F
although with one caveat - it is better to run this BAT in the As Administrator mode, so that also elevated CMDs get closed


Thank you both for making me learn something today