vb.net .vb Help, trouble with Process p.Close()

vmars316 621 Reputation points
2020-09-17T02:27:25.637+00:00

Hello & Thanks ;
WIn 10 vs 2019

p.Close() not working for me .    
        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  

It seems to be running fine , but it doesnt 'End Task' .
Please , what am I doing wrong ?
Is there another way ?
Thanks for your Help...
Here is the full program code .

' MouseUp Code from Daniel Zhang-MSFT   
' https://learn.microsoft.com/en-us/answers/questions/93390/vs-2019-vbnet-vb-how-to-capture-a-mouseup-event-in.html?childToView=94498#answer-94498   
Public Class Form1  
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load  
        '        WebBrowser1.DocumentText =  
        '    "<html><body>Please enter your name:<br/>" &  
        '    "<input type='text' name='userName'/><br/>" &  
        '    "<a href='http://www.microsoft.com'>continue</a>" &  
        '    "</body></html>"  
        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  
        MsgBox("WebBrowser1_Navigating-To  " & e.Url.ToString)  
        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  
Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,875 questions
0 comments No comments
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,621 Reputation points
    2020-09-17T05:37:01.073+00:00

    Hi Vernon Marsden,
    In your another thread, I have explained in detail that Process.Close() method is used to free all the resources that are associated with this component.
    And you can use Process.Kill() or Process.CloseMainWindow() method to stop the associated process.
    Does this solution work for you? If not, what problem did you encounter? If it is resolved, please click "Accept Answer".
    For the same problem, we suggest discussing on a thread instead of creating a new one.
    Thank you for your understanding.
    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

1 additional answer

Sort by: Most helpful
  1. vmars316 621 Reputation points
    2020-09-17T18:05:50.233+00:00

    Thanks Daniel ;
    I read elsewhere that .p.Close() is best to use because it will not only Close but will allow the process to clean up its ,resources , Close neatly ,
    where as p.Kill() will just kill it and all its resources .
    But I just now tried .p.Kill and it works great .

    I lost track of the other post , thought I had marked you as Answered .
    My apologies .
    Thanks