Imports System.Reflection

Public Class frmProcessCapture
    Public ProcessId As Integer
    Public ProcessName As String
    Public WindowTitle As String

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Dim oWindow = ClassWindowAPI.GetWindowInfo()

        If oWindow Is Nothing Then
            Exit Sub
        End If

        Dim oProgramName As String = Assembly.GetEntryAssembly().GetName().Name

        If oWindow.ProcessName <> oProgramName Then
            txtPID.Text = oWindow.ProcessId
            txtName.Text = oWindow.ProcessName
            txtWindowTitle.Text = oWindow.WindowTitle
            ProcessId = oWindow.ProcessId
            ProcessName = oWindow.ProcessName
            WindowTitle = oWindow.WindowTitle

            Button1.Enabled = True
        End If
    End Sub

    Private Sub frmProcessCapture_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
    End Sub
End Class