Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catch security alert events

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.

like image 953
SkorPPio Avatar asked Feb 07 '26 12:02

SkorPPio


1 Answers

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
like image 106
SkorPPio Avatar answered Feb 09 '26 10:02

SkorPPio