简体   繁体   English

有没有办法从VB.NET控制第三方EXE文件?

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

My goal is to control an application from VB.NET . 我的目标是从VB.NET控制应用程序。 There is no API, and I do not have the source, only the compiled EXE file. 没有API,并且我没有源,只有编译的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? 有没有办法在应用程序中读取文本框的内容?

Yes, with Windows Vista (or Windows 7, or Windows Server 2003 and later) there are " UI Automation " APIs. 是的,在Windows Vista(或Windows 7或Windows Server 2003及更高版本)中,有“ UI自动化 ” API。

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. System.Windows.Automation是.NET 3.0附带的一个,它是WPF的一部分。尽管System.Windows.Automation是WPF的一部分,但它并不要求目标应用程序使用WPF。

You can read more: 您可以阅读更多内容:

Yes, you can, but first it might be easier to use ' AutoIt ' as a prototyping script first to find the application. 是的,您可以,但是首先使用AutoIt作为原型脚本可能更容易找到应用程序。 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... 查找该应用程序窗口的句柄,枚举该窗口的子控件,专门查找该文本框和该按钮……一旦AutoIt原型工作,然后深入进行实际编码,就可以使用P /调用枚举并找到窗口,获取它的句柄并对其执行自动化...

Have a look at the sample in C# from Stack Overflow posting Calling SendMessage (P/Invoke) keeps crashing . 看一下Stack Overflow发布的C#中的示例, 调用SendMessage(P / Invoke)一直崩溃 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. OP试图访问第三方窗口应用程序,提取文本并在程序中使用这些文本...请注意,在给定的链接中,如何使用“ FindWindow”在主进程窗口的子窗口中进行迭代。

Yes, but you will have to resort to using native API calls such as EnumWindows and EnumChildWindows for example. 是的,但是您将不得不使用本机API调用,例如EnumWindowsEnumChildWindows Take a look at How To Enumerate Windows Using the Win32 API . 看一下如何使用Win32 API枚举Windows It is for Visual Basic 6.0, but the concept is the same. 它适用于Visual Basic 6.0,但概念相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM