抓住安全警报事件 [英] Catch security alert events

查看:109
本文介绍了抓住安全警报事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何赶上与以下 webbrower1 安全消息事件:

How do I catch the event related to the following webbrower1 security messages:

我已经尝试使用导航的导航 DocumentTitleChanged FileDownload EncryptionLevelChanged NewWindow ,但没有成功。

I've try using Navigated, Navigating, DocumentTitleChanged, FileDownload, EncryptionLevelChanged and NewWindow, but without success.

推荐答案

我终于找到赶上通过以下code这些安全事件的方式:

I've finally find the way to catch these security events by using the following code :

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

这篇关于抓住安全警报事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆