Tito
Tito

Reputation: 105

How to control an outside executable application?

I have my own application on python 2.7. I want to control an outside .exe application. I'm able to launch such an application, klm.exe as:

from win32com.client import *

ExtApp = Dispatch("Wscript.Shell")
ExtApp.Run("E:\XYZ\ABC\klm")

But I want to have full control of this outside .exe application as it has tabs, radio buttons, push buttons, etc.

Is there a way to do so?

Upvotes: 1

Views: 1385

Answers (1)

abarnert
abarnert

Reputation: 365657

But I want to have full control of this outside .exe application as it has tabs, radio buttons, push buttons, etc.

Is there a way to do so?

Yes, multiple ways, depending on the application.

Since you're already using COM (although I'm not sure why you're using it just to launch apps)… does the app have a COM automation (IDispatch) interface? If so, there will probably be documentation showing how to use it from VB# (or VBScript or C# or …), which you can easily adapt to Python and win32com. (For an example of such an application, see the Outlook automation docs.)

If there's no COM automation interface, there may still be a lower-level COM interface, which is almost as easy to use via win32com, but it usually won't provide any access to the GUI controls; instead, you'll be talking to the same lower-level functionality that the GUI uses. (For a good example, see Apple's iTunes COM Interface.)

If there's no COM support at all, the simplest thing to do is to automate it via Windows WM_* events. There are some examples of doing that in the pywin32 documentation, but there are also a lot of higher-level wrappers, like AutoPy and pywinauto/swapy, and so on that will make things a whole lot easier. There are dozens of these, free and commercial, and even more if you're willing to step outside of Python and use a different scripting system, and SO is not a good place to discuss the pros and cons of each.

Finally, you can always ignore the app's windows and just automate the system mouse… but this is almost always a silly thing to do.

Upvotes: 1

Related Questions