Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1670
  • Last Modified:

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



0
vamail2
Asked:
vamail2
  • 2
1 Solution
 
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
 
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:
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

Featured Post

Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now