Vous êtes sur la page 1sur 4

Command Line Task Management

http://www.petri.co.il/command-line-task-management.htm[5/27/2014 5:21:11 PM]


Introduction
Managing processes on remote computers is a typical task for the IT Pro. We have a number of
tools at our disposal, including Windows PowerShell. But Im a big believer in the right tool for
the job. Sometimes you need a quick way to manage processes on remote machines. For those
situations, the legacy CMD.EXE prompt still has much to offer.
The first command to check out is TASKLIST.EXE. Open a CMD.EXE prompt and run:
C: \ > t askl i st / ?
Figure 1 - Tasklist.exe Help
To connect to a remote computer, which is most likely, use the /S parameter followed by the
computername. The utility will use your current credentials to authenticate but you can specify
alternate credentials with the /U and /P passwords.
C: \ > t askl i st / s chi - f p01
Figure 2 - Tasklist for a remote computer
By default you get all processes, but you can do some basic filtering using the /FI parameter.
After the parameter, specify a filtering expression using these operators and key words.
Filters:
Command Line Task Management
http://www.petri.co.il/command-line-task-management.htm[5/27/2014 5:21:11 PM]
Fi l t er Name Val i d Oper at or s Val i d Val ue( s)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
STATUS eq, ne RUNNI NG |
NOT RESPONDI NG | UNKNOWN
I MAGENAME eq, ne I mage name
PI D eq, ne, gt , l t , ge, l e PI D val ue
SESSI ON eq, ne, gt , l t , ge, l e Sessi on number
SESSI ONNAME eq, ne Sessi on name
CPUTI ME eq, ne, gt , l t , ge, l e CPU t i me i n t he f or mat
of hh: mm: ss.
MEMUSAGE eq, ne, gt , l t , ge, l e Memor y usage i n KB
USERNAME eq, ne User name i n [ domai n\ ] user
f or mat
SERVI CES eq, ne Ser vi ce name
WI NDOWTI TLE eq, ne Wi ndow t i t l e
MODULES eq, ne DLL name
Therefore, if I wanted to find all processes using more than 50MB I might use an expression like
this:
C: \ > t askl i st / f i " memusage gt 50000"
I can get even more detail using the /V parameter. If you do that, you might want to change the
formatting. The default is a table but you can use /FO and specify List or CSV.
C: \ > t askl i st / f i " memusage gt 50000" / v / f o Li st
Figure 3 - Tasklist Filtering
The other feature I really like is the ability to discover what processes are running for differing
services, especially all those svchost processes.
C:\> tasklist /s chi-fp01 /svc
Command Line Task Management
http://www.petri.co.il/command-line-task-management.htm[5/27/2014 5:21:11 PM]
Figure 4 - Tasklist Services
The other side to process management is killing processes. For that, we have a complementary
TASKKILL.EXE command. This utility uses almost the same syntax as TASKLIST.EXE.
Figure 5 - Taskkill.exe
I can kill processes by ID, name or some other filter. For example, Notepad is running on a
remote computer and I want to terminate the process. This is a simple command from my
Windows 7 desktop.
C:\>taskkill /s chi-fp01 /im notepad.exe
Figure 6 - Killing a Remote Process
If there were multiple instances of Notepad open, all of them would be terminated. One thing to
be careful of is that there is no WhatIf or Confirm like there is in PowerShell. However, because
the syntax is so similar between the two commands you can first check for the processes.
C: \ >t askl i st / s chi - f p01 / f i " i magename eq not epad. exe"
Command Line Task Management
http://www.petri.co.il/command-line-task-management.htm[5/27/2014 5:21:11 PM]
If these are the processes you want to kill, press the Up arrow, move the cursor to the beginning
of the line and change the command to taskkill.
C: \ > t askki l l / s chi - f p01 / f i " i magename eq not epad. exe"
Conclusion
Using these command lines tools doesnt require any special skill and nothing extra has to be
installed or configured. They should work in most domain environments and if you want to
automate a little bit, they certainly lend themselves to batch file scripting.

Vous aimerez peut-être aussi