未加星标

Kill all matching processes on Windows from command prompt

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二04 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

Everyone knows how to kill a process in windows using Task Manager. However, when you’re on a Terminal Server Environment with 20 other users and you need to kill all matching processes on Windows from Command prompt it is just not possible because there might be 100 processes running. But hey, if you ask me, I would simply force disconnect all users using Task Manager but then I might get into trouble! :grin: Anywho, you can use tasklist to list all Windows processes and taskkill to kill all matching processes on Windows from command prompt, similar to kill or kill -9 on linux. The best part (knowing Windows and all, you can actually search and match filters while doing it; no … it doesn’t have grep but similarish!)

All of this is possible with the TaskKill command. First, let’s cover the basics. You can kill a process by the process ID ( PID ) or by image name ( EXE filename).

Open up an Administrative level Command Prompt and run tasklist to see all of the running processes:

C:\WINDOWS\system32>tasklist Image Name PID Session Name Session# Mem Usage ========================= ======== ================ =========== ============ System Idle Process 0 Services 0 8 K System 4 Services 0 9,720 K Registry 120 Services 0 9,668 K smss.exe 444 Services 0 484 K csrss.exe 628 Services 0 2,004 K wininit.exe 732 Services 0 3,256 K services.exe 804 Services 0 7,584 K lsass.exe 824 Services 0 12,408 K svchost.exe 996 Services 0 344 K svchost.exe 96 Services 0 19,960 K fontdrvhost.exe 364 Services 0 768 K svchost.exe 928 Services 0 10,700 K svchost.exe 1040 Services 0 5,244 K svchost.exe 1296 Services 0 2,300 K svchost.exe 1304 Services 0 5,376 K

In the example above you can see the image name and the PID for each process. If you want to kill the firefox process run:

C:\>Taskkill /IM firefox.exe /F

or

C:\>Taskkill /PID 26356 /F

The /F flag is kills the process forcefully. Failure to use the /F flag will result in nothing happening in some cases. One example is whenever I want to kill the explorer.exe process I have to use the /F flag or else the process just does not terminate.

If you have multiple instances of an image open such as multiple firefox.exe processes, running the taskkill /IM firefox.exe command will kill all instances. When you specify the PID only the specific instance of firefox will be terminated.

The real power of taskkill are the filtering options that allow you to use the following variables and operators.

Variables: STATUS IMAGENAME PID SESSION CPUTIME MEMUSAGE USERNAME MODULES SERVICES WINDOWTITLE Operators: eq (equals) ne (not equal) gt (greater than) lt (less than) ge (greater than or equal) le (less than or equal) "*" is the wildcard.

You can use the variables and operators with the /FI filtering flag. For example, let’s say you want to end all processes that have a window title that starts with “Internet”:

C:\>taskkill /FI "WINDOWTITLE eq Internet*" /F

How about killing all processes running under the Steve account:

C:\>taskkill /FI “USERNAME eq Steve” /F

It is also possible to kill a process running on a remote computer with taskkill. Just run the following to kill notepad.exe on a remote computer called SteveDesktop:

C:\>taskkill /S SteveDesktop /U RemoteAccountName /P RemoteAccountPassword /IM notepad.exe /F

To learn more about taskkill run it with the /? command just like any other Windows command.

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

分页:12
转载请注明
本文标题:Kill all matching processes on Windows from command prompt
本站链接:https://www.codesec.net/view/611883.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(10)