Python and COM - Blowing the others away

Registering Python COM Servers

COM requires that all COM Objects be registered with the system. COM objects implemented in Python are no exception. By default no Python COM Servers are registered - they must be registered manually.

Before you can use a COM Server, it must be registered. For example, before using the "Python.Interpreter" server, or even the ActiveX Scripting Engine (both of which come with win32com) they must be registered. If you are writing a Python COM Server, you may be interested in how to register a server that you write.

How to register a server?

By convention, the Python code which implements a server is also responsible for registering itself. To register the server, simply use "Python.exe" to run the script. The instructions for a server should tell you which script contains the registration code.

See the example below to help this make some sense!

Example - Registering the Python.Interpreter test server

The Python.Interpreter server is implemented in the Python source file "win32com\servers\interp.py". To register the server, perform either of the following steps:

or

The server is now registered, and ready for use.

How to register a server that you write.

If you are writing a Python COM Server, you need to provide code to register the server.

Due to time contraints, all I have done if list the code that the "Python.Interpreter" sample uses to register its server. Note that the UUID in the sample must be changed if you adapt this code for your server.

# Actual Python Implementation code

if __name__=='__main__':

print "Registering COM server..."

from win32com.server.register import RegisterServer

RegisterServer("{30BD3490-2632-11cf-AD5B-524153480001}",

"win32com.servers.interp.Interpreter",

"Python Interpreter",

"Python.Interpreter",

"Python.Interpreter.2")

print "Class registered."