C# Word Automation:  Need process ID or Hwnd

Posted on 2011-05-11
Last Modified: 2013-12-16

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

Question by:vamail2
    LVL 17

    Expert Comment

    If you've used System.Diagnostics.Process to start your hidden version of Word, you can simply get the ProcessID from the Process object.
    LVL 21

    Accepted Solution

    You could find the process by calling EnumProcesses (

    LVL 17

    Expert Comment

    No need for a P/Invoke, you can just use the Process.GetProcesssesByName method:

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Java/J2EE and SOA

    This course will cover both core and advanced Java concepts like Database connectivity, Threads, Exception Handling, Collections, JSP, Servlets, XMLHandling, and more. You'll also learn various Java frameworks like Hibernate and Spring.

    I'm writing to share my clumsy experience in using this elegant tool so you can avoid every stupid mistake I made. (I leave it to the authorities to decide if this deserves a place in the Knowledge archives.)  Now that I am on the other side of my l…
    Preface: When I started this series, I used the term CommandBars because that is the Office Object class that it discusses. Unfortunately, when Microsoft introduced Office 2007, they replaced the standard Commandbar menus with "The Ribbon" and rem…
    This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
    Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now