enthought / enthought/comtypes

GUID not working when client.GetActiveObject is None

Open
#141 6 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
345
Forks
105
PR merge metrics
No merged PRs in 30d

Description

I'm running this script below. When I run it the first time, it should create a new instance of a program. When I run it a second time, it should be attaching to an already running instance. Instead it creates a new instance. The only thing that has changes was a windows update. I have tried running the code with Comtypes version 1.1.3, 1.1.4, and the current master.

Code:
```python
def launcher():
import comtypes.client
try:
#trys to attach to a running instance
mySapObject = comtypes.client.GetActiveObject("CSI.SAP2000.API.SapObject")
SapModel = mySapObject.SapModel
return mySapObject, SapModel
except OSError:
#if no running instance, creates new instance
print('os error')
helper = comtypes.client.CreateObject('SAP2000v19.Helper')
helper = helper.QueryInterface(comtypes.gen.SAP2000v19.cHelper)
ProgramPath = 'C:\Program Files\Computers and Structures\SAP2000 19\SAP2000.exe'
mySapObject = helper.CreateObject(ProgramPath)
mySapObject.ApplicationStart()
SapModel = mySapObject.SapModel
SapModel.File.NewBlank()
return mySapObject, SapModel
if __name__ == '__main__':
a, b=launcher()
print(a,b)
```

Run 1:
runfile('E:/0_Shortcut-/00.1 Dropbox/Dropbox/SoftwareProjects/sap control system/IEEE Objects/lib/_launcher2v2.py', wdir='E:/0_Shortcut-/00.1 Dropbox/Dropbox/SoftwareProjects/sap control system/IEEE Objects/lib')
os error

Run 2:
runfile('E:/0_Shortcut-/00.1 Dropbox/Dropbox/SoftwareProjects/sap control system/IEEE Objects/lib/_launcher2v2.py', wdir='E:/0_Shortcut-/00.1 Dropbox/Dropbox/SoftwareProjects/sap control system/IEEE Objects/lib')
os error

Run 3:
comtypes.client.GetActiveObject("CSI.SAP2000.API.SapObject")
Traceback (most recent call last):

File "", line 1, in
comtypes.client.GetActiveObject("CSI.SAP2000.API.SapObject")

File "E:\pyth\lib\site-packages\comtypes\client\__init__.py", line 173, in GetActiveObject
clsid = comtypes.GUID.from_progid(progid)

File "E:\pyth\lib\site-packages\comtypes\GUID.py", line 78, in from_progid
_CLSIDFromProgID(str(progid), byref(inst))

File "_ctypes/callproc.c", line 918, in GetResult

OSError: [WinError -2147221005] Invalid class string

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.