-2

How to close (terminate) Windows applications using Python script? When I switch-on my PC, I find many applications like MSOSYNC.exe, ONENOTEM.exe etc. along with many others, running, which are not very useful. I want to close those? I tried "subprocess" module and some other, they not working. Which method should I use?

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • I don't use Windows much, but I believe the command you are looking for is `taskkill`. However, you have to know the name (which will kill all Notepads) or the PID (which you have to find out, which is harder) of the process. – Arc676 May 23 '16 at 09:09
  • I'd have thought a simple batch-script would serve you purposes better. Why involve Python? – SiHa May 23 '16 at 09:38

1 Answers1

0

You're using the Popen class to construct a new object in you example already. It has methods to deal with it. Read the documentation

import subprocess
proc = subprocess.Popen(['c:\\windows\\system32\\notepad.exe','C:\\file1.txt'])
proc.terminate()
renefritze
  • 2,167
  • 14
  • 25
  • Actually that was just an example. When I switch-on my PC, I find many applications running, half of them serve no purpose. The Idea is to close all those unnecessary applications by executing one simple python file. So, command "proc.terminate()" may not work. – python-king May 23 '16 at 09:31