如何捕获与以下webbrower1
安全消息相关的事件:
我尝试使用Navigated
,Navigating
,DocumentTitleChanged
,FileDownload
,EncryptionLevelChanged
和NewWindow
,但没有成功。
答案 0 :(得分:1)
我终于找到了使用以下代码捕获这些安全事件的方法:
Public Class Form1
Dim WebBrowserReady = False
Dim securityAlertEvent_1 = False
Dim securityAlertEvent_2 = False
Private Sub bRunReportID_Click(sender As Object, e As EventArgs) Handles bRunReportID.Click
Try
webBrowser1.Navigate("https://...")
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Private Sub webBrowser1_ProgressChanged(sender As Object, e As WebBrowserProgressChangedEventArgs) Handles webBrowser1.ProgressChanged
Dim nWnd As IntPtr
Dim nWnd2 As IntPtr
Dim ceroIntPtr As New IntPtr(0)
Dim Wnd_name As String
Dim Wnd_name2 As String
Wnd_name = "Security Alert"
nWnd = FindWindow(Nothing, Wnd_name)
Wnd_name2 = "Windows Security"
nWnd2 = FindWindow(Nothing, Wnd_name2)
If nWnd.Equals(ceroIntPtr) Then
'do nothing
Else
If securityAlertEvent_1 = False And securityAlertEvent_2 = False Then
SendKeys.SendWait("{ENTER}")
securityAlertEvent_1 = True
ElseIf securityAlertEvent_1 = True And securityAlertEvent_2 = False Then
SendKeys.Send("{LEFT}")
SendKeys.SendWait("{ENTER}")
securityAlertEvent_2 = True
Else
'do nothing
End If
End If
If nWnd2.Equals(ceroIntPtr) Then
'do nothing
Else
SendKeys.Send("username")
SendKeys.Send("{TAB}")
SendKeys.Send("password")
SendKeys.SendWait("{ENTER}")
End If
End Sub
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Function FindWindow2 Lib "user32" Alias "FindWindowW" (
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
Private Declare Function SetForegroundWindow Lib "user32" Alias "FindWindowW" (
ByVal hWnd As IntPtr) As Long
End Class