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..



vamail2Asked:
Who is Participating?
 
MogalManicCommented:
You could find the process by calling EnumProcesses (http://pinvoke.net/default.aspx/psapi/EnumProcesses.html)

0
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
If you've used System.Diagnostics.Process to start your hidden version of Word, you can simply get the ProcessID from the Process object.
0
 
Jesse HouwingScrum Trainer | Microsoft MVP | ALM Ranger | ConsultantCommented:
No need for a P/Invoke, you can just use the Process.GetProcesssesByName 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.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.