3

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

enter image description here

enter image description here

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

noseratio
  • 59,932
  • 34
  • 208
  • 486
SkorPPio
  • 43
  • 3
  • 8
  • That's not possible. This dialog is displayed by the browser and is hack-proof. For obvious reasons, don't visit insecure web sites. If this is important then there's a web server admin that you need to wake up. – Hans Passant Nov 28 '13 at 23:47
  • Possibly a duplicate of http://stackoverflow.com/questions/6933254/webbrowser-control-ignore-ssl-errors – noseratio Nov 29 '13 at 01:37

1 Answers1

1

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
SkorPPio
  • 43
  • 3
  • 8