Detecting a message box open in another application

I am developing a Windows service in VB.NET that runs an outdated application that does some work. The service acts as a wrapper around an inherited application, allowing users to automate manual control otherwise.

Everything works fine, except that the legacy application displays a message. When this happens, the process stops until the message box is closed.

Since the service will be running on the server, there will be no user to close the message window.

The service starts an obsolete application in System.Diagnostics.Process .

Is there a way to detect that a message box was shown by a process that I started using System.Diagnostics.Process ? And is there a way to close the message box through code?

+1
source share
2 answers

I also found that EnumChildWindows does not return a MessageBox. But I found a site that showed me how to do this. http://vbcity.com/forums/t/105842.aspx You want to call GetWindow passing in GW_ENABLEDPOPUP. It worked like a charm. Thanks to Scott Valetsko!

+2
source

Use FindWindow to find the application, use EnumChildWindows to list all the child windows until you find the message (if the message box is not a direct child of the main application window, you may need a recursive I think).

You might be able to skip the FindWindow call and use the MainWindowHandle property of the Process instead, but I have not tested whether this works.

A good tool to view all of this is Spy ++, which can help you see some of the information you can get about a running process.

+1
source

Source: https://habr.com/ru/post/985054/


All Articles