【问题标题】:Catch security alert events捕获安全警报事件
【发布时间】:2013-12-14 19:02:17
【问题描述】:

如何捕获与以下webbrower1 安全消息相关的事件:

我尝试使用NavigatedNavigatingDocumentTitleChangedFileDownloadEncryptionLevelChangedNewWindow,但没有成功。

【问题讨论】:

  • 这是不可能的。此对话框由浏览器显示并且是防黑客攻击的。出于显而易见的原因,请勿访问不安全的网站。如果这很重要,那么您需要唤醒一个 Web 服务器管理员。

标签: vb.net browser webbrowser-control


【解决方案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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-14
    • 1970-01-01
    • 1970-01-01
    • 2011-12-04
    • 2011-11-21
    • 2013-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多