Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can one control third party app which has no API? [closed]

I need to control some third party app which has no API and very limited command line arguments. So I need to simulate user interaction using .net and C#.

What I need to do:

  • start the application (this works)
  • enter string into appropriate edit fields
  • press button
  • extra bonus is to hide app window

Can this be done and how ?

Thank you very much.


EDIT: What do you think about AutoIt tool ?

like image 383
Primoz Avatar asked Jan 20 '23 01:01

Primoz


2 Answers

You could achieve this using White.

It enables you to programmatically simulate user interaction with Win32, WinForms, WPF, Silverlight and SWT applications. I used it years ago when it first can out to automate some simple smoke tests on a WinForms application with great success.

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

I created some code to launch my application and find a series of controls by name. Once found, each control could be manipulated (e.g. text entered, button clicked, etc...). To find the name of the controls, use something like Spy++ (Win32), UISpy (WinForms) or Snoop (WPF) to inspect the running application.

like image 184
adrianbanks Avatar answered Jan 26 '23 17:01

adrianbanks


Theres also the UI Automation API, which, for this task, would be pretty easy to whip up. This link will give you an idea of the support for each of the control types:UI Automation Control Types. You can use the control name, caption or resource ID in order to grab its handle, and do what you want. Clicking a button can be as simple as grabbing the handle and:

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

I've had very good success with this on all .net windows, and 99% of controls from the native world

like image 41
rigamonk Avatar answered Jan 26 '23 17:01

rigamonk