I create a com object in powershell like so:
$application = new-object -ComObject "word.application"
Is there a way to get the PID (or some other unique identifier) of the launched MS Word instance?
I want to check if the program is blocked e.g. by modal dialogs asking for passwords, and I can’t do it from whithin PowerShell.
Ok, I found out how to do it, we need to call the Windows API. The trick is to get the HWND, which is exposed in Excel and Powerpoint, but not in Word. The only way to get it is to change the name of the application window to something unique and find it using “FindWindow”. Then, we can get the PID using the “GetWindowThreadProcessId” function: