win32com.client.Dispatch("CorelDRAW.Application")
No version number, so it binds to whatever version is registered as default. On a machine with several versions installed you may not get the one you wanted.
Signature
Notes
Python example (runnable)
pywin32. The example assumes app / doc / page / layer are already connected.
See Connection & Initimport win32com.client
# no version number: connects to the default registered version
# with several versions installed you may land on the wrong one
app = win32com.client.Dispatch("CorelDRAW.Application")
print("Actually connected to version: ", app.Version) # check app.Version to see which one you got
Without a version suffix, Windows makes the decision for you
Drop the version from the ProgID and the registry leaves you one layer of indirection:
HKEY_CLASSES_ROOT\CorelDRAW.Application
└─ CurVer (default value) = "CorelDRAW.Application.24"
Dispatch("CorelDRAW.Application") reads that CurVer and then resolves the
concrete version it points at. So "no version" does not mean "any version works" — it means
"whichever one the registry currently names".
Who writes CurVer, and when it changes
Each version's installer, plus the COM self-registration that runs the first time that version starts. The important part: the last writer wins, not the highest version.
So this is a real scenario, and a hard one to notice. Both 2019 and 2023 are installed. One day you
double-click an old file, or launch 2019 from an old shortcut, and it re-registers the ProgID. Now
CurVer points back at .21. Your script has not changed a character, but its
behaviour has — enum constants differ, arguments are rejected, export options are missing.
That is the argument against versionless ProgIDs in production: it turns a reproducible script into something that depends on machine state.
Reading the real value
Instead of guessing a version number, ask the registry:
import winreg
def current_progid():
key = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r"CorelDRAW.Application\CurVer")
value, _ = winreg.QueryValueEx(key, "")
winreg.CloseKey(key)
return value # e.g. "CorelDRAW.Application.24"
print(current_progid())
Log that value. The next time something misbehaves, you will know which version you were actually talking to.
Enumerating the versions registered on a machine
Walk the HKEY_CLASSES_ROOT subkeys starting with CorelDRAW.Application..
One caveat you must keep in mind: present in the registry does not mean launchable.
CorelDRAW uninstalls routinely leave their COM registration behind, and those orphan keys keep showing
up in the list. Treat the result as candidates, not facts — each one has to survive an actual
Dispatch before you count it.
32-bit versus 64-bit: the quiet trap
CorelDRAW has been 64-bit since X6, and its COM registration lives in the 64-bit registry view.
32-bit Python reads the WOW6432Node branch and cannot see those keys.
The result is not a helpful message. Dispatch simply throws:
pythoncom.com_error: (-2147221164, 'Class not registered', None, None)
-2147221164 / 0x80040154 is REGDB_E_CLASSNOTREG. When you see
it, check your interpreter's bitness before you go hunting for a typo in the ProgID:
python -c "import struct,sys; print(sys.version); print(struct.calcsize('P')*8, 'bit')"
If it says 32 bit, that is your answer. Switch to 64-bit Python — COM has no cross-bitness shortcut.
When to use it, when not to
- Use it: one-off scripts for end users, tutorial examples, your own machine with a single version installed. The upside is that someone else can run it without editing a version number.
- Avoid it: production batch jobs, deployments across many machines, anything that
has to reproduce an old result. There, put the version in config, validate it against
CurVerat startup, and warn in the log instead of silently continuing.
The recommended pattern: read, connect, confirm
import logging
import winreg
import win32com.client
log = logging.getLogger(__name__)
def cur_ver():
try:
k = winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, r"CorelDRAW.Application\CurVer")
v, _ = winreg.QueryValueEx(k, "")
winreg.CloseKey(k)
return v
except OSError:
return None # not installed, or the registration was cleaned
progid = cur_ver()
if not progid:
raise SystemExit("No CorelDRAW COM registration found - install it and run it once")
log.info("connecting via %s", progid)
app = win32com.client.Dispatch(progid)
log.info("connected, app.Version=%s", app.Version)
app.Version returns the application's own version string, which is not the same thing as
the number in the ProgID — do not compare them directly. Its value is in the log line: when something
goes wrong later, you know exactly which build was running.
About this section: Connection & Init
Connection & Init — connecting to CorelDRAW over COM.
- This section has 8 entries; this is one of them.
- See the full section index: Connection & Init
Other entries in this section
- pythoncom.CoInitialize()COM initialization; it goes on the first line of the script. Any threa
- win32com.client.Dispatch("CorelDRAW.Application.21")Connect by version number; 21 is CorelDRAW 2019. If CDR is already run
- app.Visible = TrueShows the CDR window. Setting it False is faster for batch runs, but k
- win32com.client.GetActiveObject("CorelDRAW.Application.21")Attaches to an instance that is already open and never starts a new pr
- win32com.client.gencache.EnsureDispatch(progid)Once the constant cache exists you can write cdrTextShape instead of 6
- app.VersionReturns the version as a string. Use it to confirm which version you a
- app.Quit()Closes CorelDRAW entirely. Don't call it at the end of a batch job — i