CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2006
    Posts
    109

    Arrow Identifying PID of

    I use word automation and open a new word instance which opens a given document.

    Like that:

    Dim oDoc As Word.Document
    Dim oWord As New Word.Application
    oWord.Visible = False
    oDoc = oWord.Documents.Open(srcName)

    I need to identify the PID (process ID) of the newly created word instance.
    It seems that it isn't a son process of the process which called it.

    How can I find its PID?

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Identifying PID of

    Have you tried using GetCurrentProcessID API?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Aug 2006
    Posts
    145

    Re: Identifying PID of


  4. #4
    Join Date
    Dec 2006
    Posts
    109

    Re: Identifying PID of

    I dint think that would work because the new word instance is invisible hence GetWindowThreadProcessId wouldn't work?

    Is there any general rule on the PID of the word instance or the its relation with the calling process?

  5. #5
    Join Date
    May 2002
    Posts
    10,943

    Re: Identifying PID of

    How does a window being invisible keep you from getting the HWND?
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  6. #6
    Join Date
    Aug 2006
    Posts
    145

    Re: Identifying PID of

    something like this perhaps:
    Code:
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
        ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    
    Private Declare Function GetWindowThreadProcessId Lib "user32" ( _
        ByVal hwnd As Long, lpdwProcessId As Long) As Long
    
    Private Sub Command1_Click()
        Dim oWord As Word.Application
        Dim pID As Long
    
        Set oWord = New Word.Application
        GetWindowThreadProcessId FindWindow(vbNullString, oWord.Caption), pID
        Debug.Print pID
        oWord.Quit
        Set oWord = Nothing
    End Sub

  7. #7
    Join Date
    Dec 2006
    Posts
    109

    Re: Identifying PID of

    This doesn't seem to work, I get pID = 0.

  8. #8
    Join Date
    Aug 2006
    Posts
    145

    Re: Identifying PID of

    strange, I get a value

  9. #9
    Join Date
    Dec 2006
    Posts
    109

    Re: Identifying PID of

    Can you send me your source code, it would really help

    [email protected]

  10. #10
    Join Date
    May 2002
    Posts
    10,943

    Re: Identifying PID of

    Quote Originally Posted by tepez
    Can you send me your source code, it would really help
    He already posted the source code.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  11. #11
    Join Date
    Dec 2006
    Posts
    109

    Re: Identifying PID of

    I know, I ment the entire source, maybe there is something I did wrong...

  12. #12
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Identifying PID of

    Try making it visible to see if it's loading, and getting the right filename.
    That code should work, if Word is open. Look in Task Manager.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  13. #13
    Join Date
    May 2002
    Posts
    10,943

    Re: Identifying PID of

    Quote Originally Posted by tepez
    I know, I ment the entire source, maybe there is something I did wrong...
    He did post the entire source. It was an example code for you to follow. Do as dglienna suggested. Task manager can also list the PID column.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured