Link to home
Start Free TrialLog in
Avatar of vamail2
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..



Avatar of Jesse Houwing
Jesse Houwing
Flag of Netherlands image

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
Avatar of MogalManic
MogalManic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.