vamail2
asked on
C# Word Automation: Need process ID or Hwnd
Hi,
I have a hidden Word process in the background. I need the ProcessID which I can get from GetThreadProcessID() if I have the HWND. Excel has an Hwnd variable as does PowerPoint. But...not Word. None that I could find unless it is hidden deep down inside some class.
The problem with FindWindow is they may have other versions of Word running so I wouldn't know if its the one I just launched hidden.
Any ideas would be appreciated..
I have a hidden Word process in the background. I need the ProcessID which I can get from GetThreadProcessID() if I have the HWND. Excel has an Hwnd variable as does PowerPoint. But...not Word. None that I could find unless it is hidden deep down inside some class.
The problem with FindWindow is they may have other versions of Word running so I wouldn't know if its the one I just launched hidden.
Any ideas would be appreciated..
If you've used System.Diagnostics.Process to start your hidden version of Word, you can simply get the ProcessID from the Process object.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No need for a P/Invoke, you can just use the Process.GetProcesssesByNam e method:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.getprocessesbyname.aspx
The disadvantage is that you do not know which instance of Word would be the one you're looking for, unless you run it under a specific account.
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.getprocessesbyname.aspx
The disadvantage is that you do not know which instance of Word would be the one you're looking for, unless you run it under a specific account.