2

At some point, I can't use Quit(). So, I need to find the PID and kill the process using psutil or os.kill

I already look at existing answers on StackOverflow but can't find them for PowerPoint. I already tried this, and it works on Excel but not PowerPoint. On PowerPoint Hwnd does not return Hwnd ID as Excel does.

Code:

import win32process
import win32com.client

app = win32com.client.Dispatch('PowerPoint.Application')
t, p = win32process.GetWindowThreadProcessId(app.Hwnd)  # app.Hwnd returns "<bound method Hwnd of <COMObject PowerPoint.Application>>"
print('PowerPoint PID : ' + str(p))
Zigatronz
  • 134
  • 1
  • 8
  • What happens if you have `app.Hwnd()`? – CristiFati Mar 30 '23 at 06:54
  • I don't know if it has it, I can't find the documentation after all. – Zigatronz Mar 30 '23 at 08:06
  • No, based on your output/error, I was asking what happens if you have `t, p = win32process.GetWindowThreadProcessId(app.Hwnd())`. I didn't suggest looking into the docs or smt like that. Because the question is lacking the actual code output ([\[SO\]: How to create a Minimal, Reproducible Example (reprex (mcve))](https://stackoverflow.com/help/minimal-reproducible-example)). – CristiFati Mar 30 '23 at 08:08
  • Try using the python multiprocessing libray and [multiprocessing.active_children](https://docs.python.org/3/library/multiprocessing.html#multiprocessing.active_children) to get the child processes of the python process. – Alias Cartellano Mar 30 '23 at 21:31

0 Answers0