简体   繁体   English

在C#中从第三方应用程序获取文本框值

[英]Getting textbox value from a 3rd party app in C#

I am trying to develop a background working C# application, that needs to detect when a random 3rd party application is opened, filled out and a button is clicked. 我正在尝试开发可在后台运行的C#应用​​程序,该应用程序需要检测何时打开,填写了一个随机的第三方应用程序并单击了一个按钮。

I know i can get some info for the 3rd party app as a process, but is it possible to iterate through all of it's controls and get their values? 我知道我可以通过流程获取第三方应用程序的一些信息,但是是否可以遍历所有控件并获取其值?

I've read something about "anonymous pipes" but don't know if those could be implemented in a case like this one, and how. 我已经读过一些有关“匿名管道”的内容,但不知道在这种情况下是否可以实现这些功能,以及如何实现。

My final goal is to get the value of one specific textbox in the app, when a "Print" button is clicked in that same app. 我的最终目标是在同一应用程序中单击“打印”按钮时获得该应用程序中一个特定文本框的值。 The third party app was not developed by me, so i only have it as an .exe but i can see that it has textboxes, labels and buttons. 第三方应用不是我开发的,因此我只将其作为.exe拥有,但我可以看到它具有文本框,标签和按钮。

What you need is inter-process communication There are multiple approaches to solve your problem : 您需要的是进程间通信有多种方法可以解决您的问题:

1. Using common data store 1.使用通用数据存储

On click of print button you can set some flag and the textbox text in the database / file. 单击打印按钮后,您可以在数据库/文件中设置一些标志和文本框文本。 the other application can poll to check if this flag is set. 另一个应用程序可以轮询以检查是否设置了此标志。

Once this is set, the other application can read this from database / file. 设置完后,其他应用程序可以从数据库/文件中读取该内容。

2. You can have a Net Pipe Binding WCF endpoint hosted from the other application. 2.您可以从另一个应用程序托管一个Net Pipe Binding WCF终结点。

I would prefer this option if I have to send data from one process to other process on same machine. 如果我必须将数据从一个进程发送到同一台计算机上的另一个进程,我会更喜欢此选项。
Your main appplication will have proxy of wcf service. 您的主要应用程序将具有wcf服务的代理。 Wcf service will be part of other application which needs to know textbox text. Wcf服务将成为其他需要了解文本框文本的应用程序的一部分。

On click of "Print" button, your main application will send text box text to this WCF service. 单击“打印”按钮后,您的主应用程序会将文本框文本发送到此WCF服务。

Because this is using Named Pipe binding, this service would be available only from that machine. 因为这是使用命名管道绑定,所以该服务仅可从该计算机上使用。

Refer example from this blog . 请参阅此博客中的示例。

There can be other ways too (eg hosting web api which allows access from localhost only). 也可以有其他方法(例如,托管仅允许从本地主机访问的Web API)。 The choice of approach depends on high level design of your programs. 方法的选择取决于程序的高级设计。

Hope this helps 希望这可以帮助

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

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