FindWindowEx找不到通过远程桌面连接显示的MessageBox

时间:2015-05-08 07:31:44

标签: python winapi pywin32 findwindowex

我们有一台构建机器,我们每天都会在我们开发的应用程序上构建和执行测试。问题是某些测试失败了,因为我们的一些可执行文件崩溃了。如果它们会正常崩溃,那将只是一次失败的测试。

但不是这样,他们失败了一个阻止他们完成的弹出窗口。他们将在一段确定的时间(通常5-10分钟)后被杀死。我们通过创建一个" watchdog"来克服这个问题。定期检查弹出窗口并在找到时关闭它们。用于检查的python代码在这里:

def CheckGenericPopupByClassName(hwnd,className):
    # pass None for desktop popups

    hwndPopup = None
    hwndFirst = None
    consecutiveExceptionCount = 0
    # check for popups on Desktop
    while True:
        try:
            hwndPopup = win32gui.FindWindowEx(hwnd, hwndPopup, className, None) # Check with Spy++ for class name
        except Exception as e:
            print("CheckGenericPopupByClassName exception:"+str(e))
            hwndPopup = hwndFirst = None
            consecutiveExceptionCount = consecutiveExceptionCount + 1
            if consecutiveExceptionCount > 5:
                return
            continue

        consecutiveExceptionCount = 0

        if hwndPopup is None or hwndPopup is 0 or hwndPopup is hwndFirst:
            break

        if hwndFirst is None:
            hwndFirst = hwndPopup

        HandleGenericPopup(hwndPopup) # this closes the popup

问题是MessageBox高于远程桌面连接登录,而前一种方法找不到。登录到远程桌面连接后,定期调用的函数会找到弹出窗口。

MessageBox来自csrss.exe(我在Process Explorer中看到过)并且有以下文字:

" XXXXX.exe - 应用程序错误"

"< ...>处的指示< ...>引用的内存。无法读取内存。"

单击“确定”终止程序

单击CANCEL以调试程序

我可以这样做:Can the "Application Error" dialog box be disabled?

但我想知道为什么FindWindowEx在这种情况下找不到MessageBox。任何想法我应该怎么做才能找到MessageBox?

谢谢!

后来编辑: 可以找到禁用弹出窗口的解决方案here

1 个答案:

答案 0 :(得分:0)

我选择避免显示弹出窗口。

我使用the solution from Microsoft site