【问题标题】:VB .NET SHDocVw.InternetExplorer: Windows Security popupVB .NET SHDocVw.InternetExplorer:Windows 安全弹出窗口
【发布时间】:2020-05-09 12:16:11
【问题描述】:

您好,我正在使用 Internet Explorer 无头模式在我的脚本上执行自动化任务,但我遇到了一个问题,有时在某些页面上冲浪时会出现身份验证弹出窗口,这些窗口显示为登录页面,但不是通过 HTML弹出窗口,但更多的是窗口弹出窗口。

我想控制弹出窗口,所以当它弹出时,它将在 TOP 上可见。现在它非常随机,有时会显示在所有程序的顶部,但有时会在后台很远,然后自动化失败,因为用户没有看到弹出窗口。

硬编码用户名和密码不是一种选择。

有人知道我如何操纵弹出窗口(见附件中的截图)并最终至少将其放在屏幕顶部吗?

谢谢!

Windows Security Popup

【问题讨论】:

  • 您可以使用 UI 自动化检测对话框的打开,使用 WindowPattern.WindowOpenedEvent 设置事件处理程序 (Automation.AddAutomationEventHandler),从 AutomationElement.RootElement(桌面)开始,如所述 @ 987654322@。 VB.Net 代码示例,做同样的事情,here
  • 当你得到Dialog的句柄(在事件处理程序的AutomationEventArgs对象的属性中设置),你可以使用SetWindowPosSetForegroundWindow将它移到前台,因为 WindowPatter.SetWindowVisualState 方法可能无法按预期使用此类对话框。
  • @Jimi 感谢您的输入,虽然我无法实现SetForegroundWindow,但我明白了它是如何工作的,所以我使用了AppActivate

标签: vb.net popup shdocvw shdocvw.internetexplorer


【解决方案1】:

解决方案:

Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        Automation.AddAutomationEventHandler(WindowPattern.WindowOpenedEvent, AutomationElement.RootElement,
           TreeScope.Subtree,
           Sub(UIElm, evt)
           Dim element As AutomationElement = TryCast(UIElm, AutomationElement)
           If element Is Nothing Then Return
              Dim NativeHandle As IntPtr = CType(element.Current.NativeWindowHandle, IntPtr)
              If InStr(element.Current.Name, "Windows Security") > 0 Then
                    AppActivate(element.Current.ProcessId)
              End If

        End Sub)
    End Sub

【讨论】:

    猜你喜欢
    • 2013-05-16
    • 2015-02-09
    • 2022-12-14
    • 1970-01-01
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 2011-12-26
    相关资源
    最近更新 更多