COM "获取属性" 带多个参数
我想从 Python 调用 WindowsInstaller.Installer.ProductsEx,但是不知道怎么才能让它工作。
这是我想从 Python 调用的一个 VBScript 版本:
dim msi, products
set msi = CreateObject("WindowsInstaller.Installer")
set products = msi.ProductsEx("", "s-1-1-0", 7)
我觉得我的问题在于 ProductsEx
是一个只读的获取属性,它需要三个参数,而我不知道怎么让 win32com
或 comtypes
以这种方式调用它。
我尝试过:
>>> import win32com.client
>>> msi = win32com.client.Dispatch('WindowsInstaller.Installer')
>>> products = msi.ProductsEx('', 's-1-1-0', 7)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<COMObject WindowsInstaller.Installer>", line 2, in ProductsEx
pywintypes.com_error: (-2147352573, 'Member not found.', None, None)
还有类似的用法,使用 comtypes
:
>>> import comtypes.client
>>> msi = comtypes.client.CreateObject('WindowsInstaller.Installer')
>>> products = msi.ProductsEx['', 's-1-1-0', 7]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\comtypes\client\dynamic.py", line 46, in __getitem__
**dict(_invkind=comtypes.automation.DISPATCH_PROPERTYGET))
File "C:\Python27\lib\site-packages\comtypes\automation.py", line 768, in Invoke
args))
_ctypes.COMError: (-2147352571, 'Type mismatch.', ('TypeError: Parameter 1', (('', 's-1-1-0', 7),)))
我觉得在 comtypes
中更接近了,因为 DISPATCH_PROPERTYGET
是我想要做的。在这两个库中,我尝试了我能想到的每一种语法:
msi.ProductsEx(['', 's-1-1-0', 7])
msi.ProductsEx[['', 's-1-1-0', 7]]
msi.ProductsEx['']['s-1-1-0'][7]
None
代替''
- 用元组代替列表
我该如何从 Python 调用一个带有多个参数的 COM “获取”属性呢?
1 个回答
1
使用获取/设置
msi.GetProductsEx("", "s-1-1-0", 7)