开发者

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

My goal is to control an applica开发者_C百科tion 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?


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:

  • the UI Automation blog.
  • the MSDN Magazine article - talks about using PowerShell with System.Management.Automation.dll (an alternative to System.Windows.Automation).
  • Blog post by Samuel Jack - describes using System.Windows.Automation to automate the Paint.NET program (C#).
  • CodeProject article #1 shows using UI Automation to test an installer
  • CodeProject article #2 provides a basic introduction to using System.Windows.Automation


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜