【发布时间】:2015-07-19 00:58:54
【问题描述】:
我们有一台构建机器,我们在其上进行日常构建并在我们开发的应用程序上执行测试。问题是一些测试失败了,因为我们的一些可执行文件正在崩溃。如果他们会正常崩溃,那将只是一个失败的测试。
但不是那样,他们会因为弹出窗口而失败,阻止他们完成。他们会在一段确定的时间(通常是 5-10 分钟)后被杀死。我们通过创建一个“看门狗”来解决这个问题,该“看门狗”会定期检查弹出窗口并在找到时关闭它们。检查的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找到禁用弹窗的解决方案。
【问题讨论】:
-
FindWindow是错误的工具。请改用SetWinEventHook。
标签: python winapi pywin32 findwindowex