Python COM服务器与VBA延迟绑定+跳过赢得注册(没有管理员权限) [英] Python COM server with VBA late biding + skip win register (no admin rights)
问题描述
我试图 import
将Python代码插入到VBA中。
I'm trying to import
Python code into in VBA.
>需要管理员权限。有没有办法围绕赢得注册需要(假设我只是没有管理员权限),但保持迟到的行为(不要求工具>>参考每次我编译新的东西)
The code below works but requires admin rights. Is there a way to go around the win register need (assume I just don't have admin rights) but keep the 'late biding' behavior (dont want to Tools>>Reference every time I compile something new)
class ProofOfConcept(object):
def __init__(self):
self.output = []
def GetData(self):
with open('C:\Users\MyPath\Documents\COMs\SourceData.txt') as FileObj:
for line in FileObj:
self.output.append(line)
return self.output
class COMProofOfConcept(object):
_reg_clsid_ = "{D25A5B2A-9544-4C07-8077-DB3611BE63E7}"
_reg_progid_= 'RiskTools.ProofOfConcept'
_public_methods_ = ['GetData']
def __init__(self):
self.__ProofOfConcept = ProofOfConcept()
def GetData(self):
return self.__ProofOfConcept.GetData()
if __name__=='__main__':
print "Registering COM server..."
import win32com.server.register
win32com.server.register.UseCommandLine(COMProofOfConcept)
调用它的VBA代码:
Sub TestProofOfConcept()
Set PoF = CreateObject("RiskTools.ProofOfConcept")
x = PoF.GetData()
MsgBox x(0)
End Sub
推荐答案
总之,没有。 VBA运行时基本上使用 CoGetClassObject COM API下面 - CreateObject()
函数本质上只是一个薄的包装它(它调用 CLSIDFromString 从参数首先定位CLSID)。这两个函数都要求类被注册。
In short, no. The VBA runtime basically uses the CoGetClassObject COM API under the hood - the CreateObject()
function is essentially just a thin wrapper around it (it calls CLSIDFromString to locate the CLSID from the parameter first). Both of these functions require that the class be registered.
这篇关于Python COM服务器与VBA延迟绑定+跳过赢得注册(没有管理员权限)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!