0

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.

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.

Filip5991
  • 383
  • 1
  • 3
  • 13
  • https://stackoverflow.com/questions/1019790/how-to-find-a-child-of-a-parent-unmanaged-win32-app, https://stackoverflow.com/questions/8685002/how-to-read-another-windows-from-a-different-program – CodeCaster Jan 22 '19 at 14:11
  • 1
    Hmmm--you want to detect when a "random" app launches and then capture information being placed into that app's initial dialog? You wouldn't be trying to capture user names, emails, or passwords now--would you...? – Jazimov Jan 22 '19 at 15:09
  • 2
    Use [UI Automation](https://learn.microsoft.com/en-us/windows/desktop/winauto/entry-uiauto-win32). A description of the process involved [here](https://stackoverflow.com/a/54004484/7444103). – Jimi Jan 22 '19 at 16:42
  • @Jazimov that was one of my concerns too, if this is actually legal. I need the value of a textbox field that does not contain any passwords, but rather some string. The thing is the 2 applications should work as one, but I don't have the source code, and they wouldn't like any changes in the 3rd party one - so i have to find a way to process it from my c# app. – Filip5991 Jan 24 '19 at 11:06
  • @Jimi UI Automation did it for me, thank you. You can access forms through different parameters with it, and get everything you need - just like with Microsoft's Inspect – Filip5991 Jan 25 '19 at 11:05
  • @Jimi, i've encountered another problem. What if i want to monitor when a button is clicked on a form, but the form is not a process itself? In my case the main process (form) starts, and then a few buttons need to be clicked, different properties to be picked and THEN a new form opens(which isn't a process), which contains the values/buttons i need. Is there a way to monitor this? – Filip5991 Jan 29 '19 at 12:33
  • Or to explain myself better i can use a Notepad example: Let's say in an opened Notepad, i need to go File -> Save AS and a new window appears. From that new window i need some value (like the File Name) So basically, I need to do something when File Name is changed, or some button is clicked, but its NOT on the main notepad window – Filip5991 Jan 29 '19 at 12:40
  • What is the problem with that? A `WindowPattern.WindowOpenedEvent` detects the creation of **any** Window in the System, dialogs and Console uncluded. The Process will be the same, but the Automation Element will be different. In all details except the Process ones. So, if you open the Save Dialog or the Open Dialog of Notepad, you will be notified. You can then use the Element object passed in the event handler and inspect all its sub-elements. Of course, you can also interact with all the sub-elements in the tree. – Jimi Jan 29 '19 at 15:38
  • You can have some *difficulty* with some WPF applications that don't use UI Elements to show their content but instead paint the surface and modify the UI disposition using DWM and DirectX rendering. It's much more difficult to interact with these apps, but it's doable anyway. – Jimi Jan 29 '19 at 15:53

1 Answers1

2

What you need is inter-process communication There are multiple approaches to solve your problem :

1. Using common data store

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.

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 service will be part of other application which needs to know textbox text.

On click of "Print" button, your main application will send text box text to this WCF service.

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 (e.g. hosting web api which allows access from localhost only). The choice of approach depends on high level design of your programs.

Hope this helps

Manoj Choudhari
  • 5,277
  • 2
  • 26
  • 37
  • Yeah, OP might need inter-processes communication, and your ideas have some merit. But what part of "random third party app" and "I only have...an exe" did you not fully understand? :) – Jazimov Jan 22 '19 at 23:31
  • As @Jazimov mentioned, i only got an .exe so any changes to the code are impossible. – Filip5991 Jan 24 '19 at 11:07