views:

50

answers:

3

My goal is to control an application from VB.Net. There is no API, and I do not have the source, only the compiled exe. Is there a way to find the opened application, find a button within the application, click a button and know it was clicked? Is there a way to read the contents of a textbox within the application?

A: 

Yes, but you will have to resort to using native api calls such as EnumWindows and EnumChildWindows for example. Take a look here, it is for VB6 but the concept is the same.

Otávio Décio
There are managed code wrappers for the UI Automation APIs.
Cheeso
As far as I could read it requires WPF. Could be wrong though.
Otávio Décio
Interesting... I've been looking for this for some time and I've never come across this. Do you know of any samples in VB.Net?
ajl
Look for pInvoke, http://www.codeguru.com/csharp/.net/net_general/article.php/c4595 is an example.
Otávio Décio
@ajl - System.Windows.Automation was shipped *as part of* WPF, but does not require that the target app uses WPF.
Cheeso
+3  A: 

yes - with Vista (or Win7, or WS2003 and later) there are "UI Automation" APIs.

There are managed options; System.Windows.Automation is one, shipped with .NET 3.0, as part of WPF... Though System.Windows.Automation was shipped as part of WPF, it does not require that the target app uses WPF.

You can read more:

Cheeso
+1  A: 

Yes you can, but first it might be easier to use 'AutoIt' as a prototyping script first to find the application, look for the handle of the window of that application, enumerate through that window's child controls, look for that text box specifically and the button...once AutoIt prototype works, then dive into the real coding and it would be possible to use pinvokes to enumerate and find the windows, get the handles of it and perform the automation on it...

Have a look at this sample in C# for this posting here on SO. The OP was trying to access a third party window application, to extract texts and to use that texts within their program...notice how in that given link, 'FindWindow' was used to iterate through the child windows of the main process's window.

Hope this helps, Best regards, Tom.

tommieb75