views:

100

answers:

2

Hi

I'm trying to automate a hidden .NET application, with another .NET application (written in c#) using the easiest way possible. It's NOT for testing purposes, it's a way to fulfill the lack of scripting for this application.

I already tried white framework, but there is one major problems with it: the way it's working. It's slow and it's not working on hidden windows and controls (like the winAPI does). Whats more, when "clicking" white moves the mouse, brings it's targeted window to the front and so on.

I was also thinking about using a user32.dll wrapper, because the way it's handling it's target is what I need, but I've red it's not working with .NET applications. It also would be a problem working with it, because my targeted application got 5 button labeled "...", and would be really hard finding 2 of them I need. I also would like to use the controls .NET id (the name the developer gave to it's controls when designing the GUI).

BTW, my targeted application is MeGUI if that helps. We do a lot of video encoding and a tool like this would help us a lot. I need the MeGUI to be hidden, because I'm the only programmer, others using my tool shouldn't see what happens in the background, not to talk about the many windows popping all around.

+1  A: 

You can add a reference to the exe from your project and then create an AppDomain to run its main method. From there, it should be possible to queue delegates to its main thread's loop. With a bit of reflection, you could have those delegates invoke the click events and whatnot directly.

I've never attempted this approach, but it should work.

Stephen Cleary
This sounds great, but will my application remain portable after doing this? Also, I don't understand the part: "to queue delegates to its main thread's loop"
SinistraD
It should be possible to queue delegates to the main thread by calling one of its `Control.Invoke` methods. I'm not sure what you mean by "portable"; if you mean "does not require an installer", then your app would work if the controlled app doesn't require an installer. If you mean "work with different and unexpected versions of the controlled app", then the answer is no (but automating the UI would have the exact same problem).
Stephen Cleary
A: 

You should try Stephens idea instead of scripting a hidden app. A .NET Windows Forms App (EXE) is still a .NET Assembly and that means you can use that the same way as a DLL, just add a reference and use the public classes.

If you still want to try some scripting, take a look on the "Microsoft UI Automation" API and the "System.Windows.Automation" namespace.

Nice article here: http://msdn.microsoft.com/en-us/magazine/cc163465.aspx

MSDN Doc: http://msdn.microsoft.com/en-us/library/system.windows.automation.aspx

Raoni