0

I want to write a Python script/program which kills a program specified by the user.

Does anyone have an idea how to do that?

I'm pretty new to Python and I just want a little script.

Seadow11
  • 29
  • 4

1 Answers1

1

The simplest approach most likely is to write a thin wrapper around the tasklist command. It does the following:

"Displays a list of applications and services with their Process ID (PID) for all tasks running on either a local or a remote computer."

So you would spawn a process (using Python's subprocess module) to run tasklist, fetch its output (stdout), and parse the output using standard Python methods. You would look for a certain program name in the output and then identify the corresponding process ID. You can then terminate the process using os.kill().

Since you are a "noob in Python", you will probably spend quite some time learning the appropriate Python string manipulation/parsing functions, and also spend some time reading documentation about the subprocess module. All of this actually is quite simple, but you will have to invest some time -- believe me, this is worth the effort, you will learn a lot!

Dr. Jan-Philip Gehrcke
  • 33,287
  • 14
  • 85
  • 130