Try p.kill() instead of p.close().
Having probs with GetProcessesByName p.Close()
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...
2 answers
Sort by: Most helpful
-
-
Daniel Zhang-MSFT 9,626 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.