Python COM 服务器 VBA 延迟出价 + 跳过获胜注册(无管理员权限)

Python COM server with VBA late biding + skip win register (no admin rights)

我正在尝试 import Python 编码到 VBA。

下面的代码有效,但需要管理员权限。有没有办法绕过 win 寄存器需求(假设我只是没有管理员权限)但保持 'late biding' 行为(不想每次编译新东西时都使用工具>>参考)

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 under the hood - the CreateObject() function is essentially just a thin wrapper around it (it calls CLSIDFromString 首先从参数中定位 CLSID)。这两个函数都需要注册 class。