win32com 发送 32 位版本的 TestStand

win32com Dispatch the 32 bit version of TestStand

我有一个 python 脚本连接到 TestStand 并从 .seq(序列)文件中检索某些数据。

import win32com.client
import pythoncom
TestStandEngine = win32com.client.Dispatch("TestStand.Engine")
Seqfile = TestStandEngine .GetSequenceFileEx("Seq_File.seq")
Main = Seqfile.GetSequenceByName("MainSequence") #Get's the main sequence of the file

我安装了 Test Stand 2014 的 x32 和 x64 版本,脚本 运行 没问题。 卸载 x64 版本后(因为不需要),脚本现在出现此错误:

Traceback (most recent call last):
  File "C:\ts\Main.py", line 9, in <module>
    TestStandEngine = win32com.client.Dispatch("TestStand.Engine")
  File "C:\LegacyApp\Python_2.7\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
    dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
  File "C:\LegacyApp\Python_2.7\lib\site-packages\win32com\client\dynamic.py", line 114, in _GetGoodDispatchAndUserName
    return (_GetGoodDispatch(IDispatch, clsctx), userName)
  File "C:\LegacyApp\Python_2.7\lib\site-packages\win32com\client\dynamic.py", line 91, in _GetGoodDispatch
    IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
com_error: (-2147221005, 'Invalid class string', None, None)

经过一些研究,我想我知道是什么原因导致了这个问题,但我找不到任何解决方法。

-我电脑上的Python安装是32位的

>>> import platform
>>> platform.architecture()
('32bit', 'WindowsPE')

-我电脑上唯一安装的Test Stand是32位版本。

-OS : Windows x64 位 OS

这是我的猜测:我认为当它调度 Teststand.Engine 时,它会尝试使用不再安装的 x64 版本; 我试过添加 clsctx 参数,但结果相同:

win32com.client.Dispatch("TestStand.Engine",clsctx=pythoncom.CLSCTX_LOCAL_SERVER)

有什么方法可以 'force' 启动 32 位版本吗?如果 TestStand 在 32 位上并且 Python 在 32 位上,它不应该 return 一个应该与 python 32 位一起工作的 32 位 COM 对象吗?

更新: 所以在 运行 之后,在 PowerShell 中 returned 列出了 COM 的所有有效名称,但是 'Teststand.Engine' 不在列表中。列表中唯一与 TestStand 相关的对象是 TestStand.ExLauncher(我可以调度它,但它没有与 TestStand.Engine

相同的 attributes/use

通过重新安装 TestStand 解决了这个问题。 (我知道重新安装可以解决问题,但我希望我不必重新安装它,因为它会影响多个配置)

问题是,当我卸载 TestStand x64 版本时,卸载程序认为我要完全卸载 TestStand,很可能删除了一些包含 'TestStand.Engine' 指令的注册表项 重新安装 x32 位版本后,它工作正常。

您是否尝试过使用依赖于版本的界面,即

TestStandEngine = win32com.client.Dispatch("TestStand.Engine.1")