Link to home
Start Free TrialLog in
Avatar of vaultworld
vaultworld

asked on

How do I only kill/close a child window without killing the Parent all in VB.NET

How do I only kill/close a child window without killing the Parent all in VB.NET

I'm trying it with:
                    'tempProc.Kill() 'Kills all Iexplorer open
                    'tempProc.CloseMainWindow() 'Prompts to closes
But maybe I need to be working with that specific handle?


  Public Function EnumWindowsCallBack(ByVal hwnd As IntPtr, ByVal lParam As Int32) As Int32
        Dim sSave As String
        Dim ProcessID As Long

        GetWindowThreadProcessId(hwnd, ProcessID)


        Dim tempProc As Process = Process.GetProcessById(ProcessID)

        Dim processName As String = tempProc.ProcessName
       
        If (processName = "iexplore") Then


            'Get the windowtext length
            sSave = Space(GetWindowTextLength(hwnd) + 1)

            'get the window text
            GetWindowText(hwnd, sSave, Len(sSave))

            'remove the last Chr(0)
            sSave = Microsoft.VisualBasic.Left(sSave, Len(sSave) - 1)

            If (sSave.Length <> 0) Then

                If sSave.ToString.IndexOf("Google") >= 0 Then
                    sSave = "Found Google Search"

                    'tempProc.Kill() 'Kills all Iexplorer open
                    'tempProc.CloseMainWindow() 'Prompts to closes

                End If

                'Error below: Reference to a non-shared member requires an Object Reference
                Lst.Items.Add(sSave)
                'Lst.Items.Add(processName)


                If sSave.Trim <> "" Then
                    Debug.WriteLine(sSave)
                End If
            End If
        End If
        Return 1 'continue enumeration        
    End Function

ASKER CERTIFIED SOLUTION
Avatar of angus_young_acdc
angus_young_acdc
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial