Having probs with GetProcessesByName p.Close()

vmars316 621 Reputation points
2020-09-15T20:55:58.167+00:00

Hello & Thanks ;
Having probs with GetProcessesByName p.Close() .
In my kidSafeBrowser , certain sites open up IExplore ,
even though the following are coded;

        WebBrowser1.ScriptErrorsSuppressed = True
        WebBrowser1.IsWebBrowserContextMenuEnabled = False

So I want to p.Close() it .
Here is my code;

Private Sub CloseIExplore()
    Dim processArray As Process() = Process.GetProcessesByName("iexplore")
    For Each p As Process In processArray
        p.Close()
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "For Each p As Process"
    Next
    TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Private Sub CloseIExplore()"
End Sub

And here is the complete code ;

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        WebBrowser1.ScriptErrorsSuppressed = True
        WebBrowser1.IsWebBrowserContextMenuEnabled = False
        '        Me.MinimumSize = New Size(1000, 650)
        Me.StartPosition = FormStartPosition.CenterScreen
        Me.Left = 40
        Me.Top = 20
        WebBrowser1.Navigate("https://www.kidzsearch.com/")
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        AddHandler WebBrowser1.Document.MouseUp, AddressOf eventSub
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Private Sub WebBrowser1_DocumentCompleted"
    End Sub
    Sub eventSub(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs)
        Dim event_html As New HtmlElementEventHandler(AddressOf webMouseUp)
        event_html.Invoke(sender, e)
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Sub eventSub"
    End Sub
    Sub webMouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.HtmlElementEventArgs)
        If e.MouseButtonsPressed = Windows.Forms.MouseButtons.Left Then
            '            MsgBox("left clicked!")
        End If
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Sub webMouseUp"
        CloseIExplore()
    End Sub
    Private Sub WebBrowser1_Navigating(sender As Object, e As WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating
        '        If e.Url.ToString.Contains("about:blank") Or e.Url.ToString.Contains("xbox.com") Then
        '            e.Cancel = True
        '            End If
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & e.Url.ToString

    End Sub
    Private Sub CloseIExplore()
        Dim processArray As Process() = Process.GetProcessesByName("iexplore")
        For Each p As Process In processArray
            p.Close()
            TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "For Each p As Process"
        Next
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "Private Sub CloseIExplore()"
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        WebBrowser1.GoBack()
    End Sub

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        CloseIExplore()
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "----"
        TextBox1.Text = TextBox1.Text & ControlChars.NewLine & "----"
    End Sub
End Class

Code doesnt Close IExplore .
Thanks for your Help...

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,836 questions
{count} votes

2 answers

Sort by: Most helpful
  1. MotoX80 31,976 Reputation points
    2020-09-16T01:57:55.287+00:00

    Try p.kill() instead of p.close().

    0 comments No comments

  2. Daniel Zhang-MSFT 9,616 Reputation points
    2020-09-16T02:08:32.537+00:00

    Hi Vernon Marsden,
    The Process.Close() method isn't meant to abort the process. It's just meant to free all the resources that are associated with this component.
    So you can use Process.Kill() or Process.CloseMainWindow() method to stop the associated process.
    And CloseMainWindow enables an orderly termination of the process and closes all windows.
    Based on your code, you can change p.close() to p.CloseMainWindow() or p.kill().
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments