[python-win32] Windows automation basics

Andreas Holtz A.Holtz at gmx.net
Wed Mar 5 21:34:14 CET 2014


Hi Alan,

1.) Try to get the documentation of the program. ;-)
Or check the registry by searching for "YourApplication.Application" or just try it with
win32com.client.Dispatch("YourApplication.Application") in Python with win32com installed.

Checkout MakePy from PythonWin (installs with the win32com, I think) as described here:
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html

Also you can use the VB-Editor from Office to determine available libraries. In Word/Excel press ALt+F11, then Extras/Links.

And check if the program has a macro recorder. If the code looks like VB it is quite likely to have something, I asume.

2.) Read the documentation of the program *again*
or see at 3.)

3.) Programming against COM in Python is quite straightforward. Look how it is done in VB then make it identical (but nicely) in Python.
Sometimes there are some quirks (like when functions in VB work as setters foo.bar() = newValue), but win32com offers often solutions for 
this (in the example Python creates a setter, if I remember correctly)

For Office checkout the Microsoft website. I have to admit its a pain in the ass to find something there, but I eventually got the Word 
reference as an example:
http://msdn.microsoft.com/en-us/library/office/ff837519%28v=office.15%29.aspx
Same works with other Microsoft products and probably for most commercial products with COM support.

Your last questions I can't answer.

Hope this helps.

Andreas

schrieb Alan Gauld am 05.03.2014 13:27:
> After a long absence(~10 years!) I'm now back to programming
> in Windows. I need to automate some workflows using COM to
> various applications (mixture of in-house and commercial).
>
> I'm having problems finding out which apps even support
> COM access and figuring out what COM objects/methods exist.
>
> I seem to recall back in my Delphi days that there were
> explorer tools for discovering some of this (WindowsSpy
> was maybe one?)
>
> So the questions are:
>
> 1) How can I determine whether an application has a COM
>     interface in the first place?
>
> 2) If it exists, how to I figure out what it supports?
>
> 3) Any recommended web sites for COM automation (not
>     necessarily in Python but that would be ideal)
>
> And for interest only, where is COM in the world
> of .NET and Windows 8+ etc? Are there better options
> today?
>


More information about the python-win32 mailing list