Home:ALL Converter>How to interact with an application programmatically

How to interact with an application programmatically

Ask Time:2009-01-05T16:53:52         Author:Mike K

Json Formatter

I am likely to be working on a few projects soon where I will need to take data from a file and input that data programmatically into another third-party (not my own) application. One problem: I have no idea how to do this.I will need to enter data (like times on a time sheet, for exampls) Can anyone steer me in the right direction to acquire this skill?

ADDITIONAL SPECS: I wrote the original post late at night so may not have been as detailed as I should have. Here is an example: My client has an ERP app that they use to collect time stamps from the line workers as they perform their jobs and get projects out the door throughout the day. This app does NOT have an API I can use to feed data into. I have heard of a guy who was able to actually push data onto the screen in this app's windows and controls programmatically, such that the data was able to be collected into, say, an Excel worksheet, then effectively uploaded into this app. Sort of a reverse screen-scrape. It's not pretty like an API would be, but it works.

I've seen app's interact with other apps in a similar way. One good example I can think of is SnagIt, the screenshot utility. You can order it to screen capture a window in a particular app, and as you move your mouse around that window, the controls under the pointer will outline in red to indicate which control it will capture for you. I think that is interesting, and probably just a step away from actually being able to type text into such a control.

Thanks for the comments and answers so far, I'm pursuing them all.

Author:Mike K,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/412598/how-to-interact-with-an-application-programmatically
Adam Neal :

You might be able to automate it with an AutoIt script. This is a simple scripting language that hides some of the complexities of sending messages to windows and controls.",
2009-01-05T13:27:53
G S :

Different applications allow you to control them programmatically in different ways. The two commonest approaches are:\n\n1) Some applications expose commandline arguments. Example:\n\nc:\\> someapp.exe arg1 arg2\n\n\nYou can call such apps from a C++ program with a call like this:\n\nSystem(\"C:\\\\>someapp.exe arg1 arg2\");\n\n\n2) Other applications may expose far more powerful, object oriented APIs. For example, Microsoft Excel lets you program it by using the App itself as an object in your C# program:\n\nExcel.Application excelApp = new Excel.App()\n\n\nOnce you have the app object, you can call methods on it to control its behaviour. You can, for instance, open a new Excel file with a subsequent call like this:\n\nexcelApp.Workbooks.Open(\"\\\\Somefile.xls\", ...);\n\n\nFor any third party app you're trying to control, you are going to have to read its documentation as to how it lets you to do that. The info on how to program Excel, for example, can be found here.",
2009-01-05T09:04:59
Jesse Pepper :

It may be very very difficult if the application is not designed to be interacted with. You will need to send mocked events (to pretend as though the mouse was doing certain things for example). One way of doing that is to write a mouse driver that doesn't connect to a real mouse. But, as I say, it depends on the application. Applications with bigger user bases often have APIs to allow programmatic interaction, or have in-built scripting capabilities (so you can kinda make the application use your code instead).",
2009-01-05T09:34:23
Zach Hirsch :

I think FindWindow and SendMessage are the functions you want to use, in general.",
2009-01-05T09:34:44
masmer78 :

I once did something like this where a windows application was controlled by a web application. I used a lot of Win32 API for that. If your application is a similar one, then look for open source Winamp remote controller for starters. ",
2009-01-05T09:16:50
Wolf5 :

Or if you want to be even more \"hacky\", start reading the program memory and inject data directly. :P\n\nBut that can be very complex, and often wont work at all because of how the program uses the memory.",
2009-01-05T13:00:15
yy