How to manage a third-party application that does not have an API?

I need to control a third-party application that has no API and very limited command line arguments. So I need to simulate user interaction using .net and C #.

What do I need to do:

  • run the application (it works)
  • enter a line in the corresponding field board
  • press the button
  • additional bonus - hide the application window

Can this be done and how?

Thank you very much.


EDIT: What do you think of the AutoIt tool?

+4
source share
2 answers

You can achieve this using White .

It allows you to programmatically simulate user interactions with Win32, WinForms, WPF, Silverlight, and SWT applications. I used it many years ago when for the first time I was able to automate some simple smoke tests in a WinForms application with great success.

(Caution: this is based on my use a while ago, so now it may be slightly different)

I created some code to run my application and search for a number of controls by name. After detection, each control can be controlled (for example, entered text, button press, etc.). To find the name of the controls, use something like Spy ++ (Win32), UISpy (WinForms), or Snoop (WPF) to check the running application.

+7
source

Theres also a UI Automation API that will be pretty easy to crack for this task. This link will give you an idea of โ€‹โ€‹the support for each type of control: Types of user interface automation control . You can use the control name, signature, or resource identifier to grab its handle and do what you want. Clicking a button can be as simple as capturing a handle and:

AutomationElement control = AutomationElement.FromHandle(controlHandle); InvokePattern ip = (InvokePattern)control.GetCurrentPattern(InvokePattern.Pattern); ip.Invoke(); 

I had very good success on all .net windows and 99% of the controls from my native world.

+2
source

Source: https://habr.com/ru/post/1346821/


All Articles