Vous êtes sur la page 1sur 5

The Windows Taskkill Utility Ever wished you could just end a few programs just by running a batch

file? Or have you ever wanted to automatically end some programs according to a certain schedule? Even if you Google, you won't be able to find a free software that will allow you to even do such simple tasks. But fret not, we will show you how to do it in this guide. And the best of all, this method is totally free of charge! How can we do that? Well, that's because Windows XP has a built-in utility that allows you to do all the above for free! This utility is called Taskkill. Most people will not have heard of it. It's designed to end one or more tasks or processes by killing the process ID or image name of the running program. Let us show you how to make use of it.

Creating A Taskkill Batch File

Take, for instance, a scenario where you want to automatically close several of your memory-hogging applications, just by executing a single batch file. This would be particularly useful when you want to play games that require a lot of memory or run a particularly memory-intensive application. There's no need for you to manually close each application. All you need to do is run that batch file and those pre-selected applications will automatically be killed, freeing up memory for your game or application. Such a batch file would be a real time saver, wouldn't it? Now, we will show you just how to do that with Taskkill. In this scenario, we will use Yahoo! Messenger and MSN Messenger as examples. First, you need to identify the Image Names (or the running executable files) of both Yahoo! Messenger and MSN Messenger. You can do so by following these steps : 1. Go to the Windows Task Manager by pressing Ctrl-Alt-Delete. Alternatively, you can right-click on your taskbar and select Task Manager from the menu. 2. Then, click on the Processes tab. Here you will be shown all the current running processes on your computer. 3. Now, look for the Image Names for Yahoo! Messenger and MSN Messenger. I've taken the liberty to highlight the two processes. The Image Name for Yahoo! Messenger is YPager.exe while the Image Name for MSN Messenger is

msnmsgr.exe. 4. After getting both Image Names, it's time to create that batch file. Fire up your Notepad (Start Menu > All Programs > Accessories > Notepad). 5. Then type this commands in Notepad. @echo off taskkill /im YPager.exe /f taskkill /im msnmsgr.exe /f The first line, @echo off, is optional. When echo is set to off, the subsequent commands are not shown on screen during their execution. You can opt not to include that line. It will not affect the execution of the batch file at all. Removing it will just allow you to see the commands being executed. In the second and third lines of taskkill /im YPager.exe /f, the batch commands are broken down like this : Taskkill - Executes the taskkill utility that's located at C:\Windows\system32\. /im YPager.exe - Specifies the image name of the process (in this case, Yahoo! Messenger) to be terminated. Use the wildcard (*) to specify all image names (not recommended). /im msnmsgr.exe - Specifies the image name of the process (in this case, MSN Messenger) to be terminated. Use the wildcard (*) to specify all image names (not recommended). /f - Specifies that process(es) are to be forcefully terminated. This parameter is ignored for remote processes; all remote processes are forcefully terminated. 6. Now, you can save the file as "taskkill.bat" (with the quotes). You can also use any file name you like, but remember to include the .bat extension. There you have it. You have just created a batch file that you can execute (by double-clicking on it) to instantly kill off both Yahoo! Messenger and MSN Messenger. Of course, you can add as many processes into the batch file as you need. Here's a copy of the batch file created.

Alternatively, you can substitute the Image Name for the PID or Process ID of the application. Here's an example :

@echo off taskkill /pid 2452 /f taskkill /pid 1480 /f Using either the Image Name or the PID has the same effect. But you will probably prefer using the Image Name since it's easier to identify the process. But if there are more than ONE instance of the same Image Name in Windows Task Manager, then logically, using the Process ID would be better if we don't want to kill all instances of the same Image Name using just a single command.

Scheduling The Batch File's Execution If you want the batch file to run at a specific time, you can do so by using the Task Scheduler. Just go to Start Menu > All Programs > Accessories > System Tools > Scheduled Tasks and click on the Add Scheduled Task to add a schedule for the batch file. So, there you have it. You can now kill off a whole bunch of applications just by using a single batch file. And you can even do it without being present! Easy, isn't it? But that's not all you can do with taskkill. Take a look at a few examples of the commands you can create with taskkill. taskkill /pid 1230 /pid 1241 /pid 1253 taskkill /f /fi "USERNAME eq NT AUTHORITY\SYSTEM" /im notepad.exe taskkill /s srvmain /f /im notepad.exe taskkill /s srvmain /u maindom\hiropln /p p@ssW23 /fi "IMAGENAME eq note*" /im * taskkill /s srvmain /u maindom\hiropln /fi "USERNAME ne NT*" /im * taskkill /f /fi "PID ge 1000" /im * If you want to create more complex commands like that, then you need to understand taskkill's syntax and parameters. Let's take a look. Syntax First, you will need to understand how taskkill commands are built. Below is taskkill's syntax, as stated in Microsoft's own documentation. Take a look. taskkill [/s Computer] [/u Domain\User [/p Password]] [/fi FilterName] [/pid ProcessID]|[/im ImageName] [/f][/t] As you can see, taskkill supports a variety of parameters. You can think of them as options. They allow you to use taskkill to perform the tasks that you want. At the very minimum, you need to include at least one parameter for taskkill to actually do something. But you can tack on up to 7 different parameters at the same time to perform very specific tasks.

Let's take a look at the different parameters that taskkill supports.

Parameters Taskkill supports 9 different parameters, but you can only create commands using anywhere from one to seven parameters at the same time. Here are the supported parameters and an explanation of what they do : /s Computer : Specifies the name or IP address of a remote computer (do not use backslashes). The default is the local computer. /u Domain\User : Runs the command with the account permissions of the user specified by User or Domain\User. The default is the permissions of the current logged on user on the computer issuing the command. /p Password : Specifies the password of the user account that is specified in the /u parameter. /fi FilterName : Specifies the types of process(es) to include in or exclude from termination. The following are valid filter names, operators, and values. Name Hostname Status Imagename PID Session CPUTime Operators eq, ne eq, ne eq, ne eg, ne, gt, lt, ge, le eg, ne, gt, lt, ge, le eq, ne, gt, lt, ge, le eg, ne, gt, lt, ge, le eq, ne eq, ne Any valid string. RUNNING|NOT RESPONDING Any valid string. Any valid positive integer. Any valid session number. Valid time in the format of hh:mm:ss. The mm and ss parameters should be between 0 and 59 and hh can be any valid unsigned numeric value. Any valid integer. Any valid user name ([Domain\]User). Any valid string. Any valid string. Value

Memusage Username Services

Windowtitle eq, ne

/pid ProcessID : Specifies the process ID of the process to be terminated. /im ImageName : Specifies the image name of the process to be terminated. Use the wildcard (*) to

specify all image names. /f : Specifies that process(es) be forcefully terminated. This parameter is ignored for remote processes; all remote processes are forcefully terminated. /t : Specifies to terminate all child processes along with the parent process, commonly known as a tree kill. /? : Displays help at the command prompt. Now, take a look again at the taskkill command examples Microsoft created : taskkill /pid 1230 /pid 1241 /pid 1253 taskkill /f /fi "USERNAME eq NT AUTHORITY\SYSTEM" /im notepad.exe taskkill /s srvmain /f /im notepad.exe taskkill /s srvmain /u maindom\hiropln /p p@ssW23 /fi "IMAGENAME eq note*" /im * taskkill /s srvmain /u maindom\hiropln /fi "USERNAME ne NT*" /im * taskkill /f /fi "PID ge 1000" /im * Try deciphering the sample taskkill commands above using the list of parameters. Do you now see what they do? Taskkill is truly a powerful tool once you learn how to use it. It's unfortunate that most people aren't even aware it exists!

Some Important Notes Here are some things that you should be aware of when creating taskkill commands.

The wildcard character (*) is accepted only when specified along with the filters. Termination for remote processes will always be done forcefully regardless of whether the /f parameter is specified. Supplying a computer name to the HOSTNAME filter will cause a shutdown and all processes will be stopped.

Vous aimerez peut-être aussi