0

I am starting a PDF, and I get a process. The PDF is shown in a Chrome window.

Then I try to find this process among the processes, but it is not there. I have even tried adding some time to wait before calling GetProcesses(), but that wouldn't change anything.

What am I missing?

Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click

    Dim sPath As String = "d:\test.pdf"

    Dim nProc As Process = System.Diagnostics.Process.Start(sPath)
    Dim iProcID As Integer = nProc.Id

    Dim allProcesses() As Process = System.Diagnostics.Process.GetProcesses

    For Each nProcess As Process In allProcesses
        If nProcess.Id = iProcID Then
            Stop 'found :-)
        End If
    Next

End Sub
Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
tmighty
  • 10,734
  • 21
  • 104
  • 218
  • 1
    The Process object that opened the PDF doesn't exist anymore after the main Chrome Process presents the PDF content in a tabbed Window. Find the Chrome Process and check the current title of its Window. – Jimi Jul 17 '22 at 00:09
  • @Jimi Wow, how do you know that? – tmighty Jul 17 '22 at 01:01
  • It's pretty common for multi-windowed processes to act like this. For example, if you open up an Excel workbook the same way, you have the same result. When the new document is opened, the Process that started it is associated to the main `EXCEL` Process and the starting Process object is destroyed right after. In TaskManger, in this case and many others, you have only one main Process (though Chrome and other Browsers may have other active Processes, but not related to the presentation of tabbed documents) – Jimi Jul 17 '22 at 06:57

0 Answers0