运行 pywin32 COM 对象作为另一个用户。

2024-04-20 10:05:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个使用COM对象的Python程序,我想远程运行它。该程序在本地计算机上运行良好,但当我在远程计算机上运行该程序并尝试使用DCOM对象远程连接到远程计算机上的COM对象时,NTLM身份验证失败(在Wireshark捕获中可以看到)。在

这台机器在一个Windows域上,但是我可以在两台机器上创建任意数量的本地用户。我已经尝试在两台计算机上创建相同的本地用户,但是DCOM对象将计算机作为域传递(即尝试使用Machine1\userMachine2进行身份验证)。在

有什么建议吗?在

有没有办法使用pythoncomwin32com指定用于NTLM身份验证的不同用户和密码?

我非常愿意回答任何问题,尽可能多地补充细节。在

代码:

print "\nConnecting to '%s'" % LAHostNameOrIP ;
try:
    LAConnect = win32com.client.Dispatch("AgtLA.Connect")
    # Fails on the LAConnect.GetInstrument call
    LAInst = LAConnect.GetInstrument(LAHostNameOrIP)
except pythoncom.com_error, (hr, msg, exc, arg):
    print "The AgtLA call failed with code: %d: %s" % (hr, msg)
    if exc is None:
        print "There is no extended error information"
    else:
        wcode, source, text, helpFile, helpId, scode = exc
        print "The source of the error is", source
        print "The error message is", text
        print "More info can be found in %s (id=%d)" % (helpFile, helpId)
    sys.exit(1)

Tags: the对象程序com身份验证source远程is