1

I am trying to kill external running applications like Windows Paint, a .mp3 and similar programs through a python script.

I open the program throughos.startfile. Any ideas how I can close the programs efficiently? I am using a Windows 7 machine. I'd appreciate the help a lot! Thanks!

2
  • Seems like the top answer to this question would do what you're looking for: stackoverflow.com/questions/5780425/… Commented Jul 11, 2011 at 4:34
  • What if I don't want to go through the subprocess method? Commented Jul 11, 2011 at 4:38

3 Answers 3

3

As of Python 2.7 os.kill works on Windows. You could find the PID using this recipe.

Sign up to request clarification or add additional context in comments.

1 Comment

You're welcome. I agree it is more complicated than I expected.
0

Popen will let you kill an opened process, but that won't prompt to save files, etc.

p = subprocess.Popen(['notepad', 'tmp.txt'])
#later
p.kill()

2 Comments

Can I open non .exe files with P.open ?
I just tried and it doesn't look like it: WindowsError: [Error 193] %1 is not a valid Win32 application
0

When you ask Windows to launch something with os.startfile(), you don't get a handle to the created process. This is because the underlying ShellExecute() function does not return a handle to the created process. I believe this is because not all actions actually result in a process being created at all (for example with in-process COM servers or other esoteria).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.