ajl
ajl

Reputation: 714

Is there a way to control a third-party EXE file from VB.NET?

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 file. 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?

Upvotes: 2

Views: 5560

Answers (3)

t0mm13b
t0mm13b

Reputation: 34598

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 P/Invoke's to enumerate and find the windows, get the handles of it and perform the automation on it...

Have a look at the sample in C# from Stack Overflow posting Calling SendMessage (P/Invoke) keeps crashing. 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.

Upvotes: 1

Otávio Décio
Otávio Décio

Reputation: 74310

Yes, but you will have to resort to using native API calls such as EnumWindows and EnumChildWindows for example. Take a look at How To Enumerate Windows Using the Win32 API. It is for Visual Basic 6.0, but the concept is the same.

Upvotes: 0

Cheeso
Cheeso

Reputation: 192657

Yes, with Windows Vista (or Windows 7, or Windows Server 2003 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 application uses WPF.

You can read more:

Upvotes: 4

Related Questions