通过服务打开powerpoint演示文稿失败

时间:2013-06-07 10:19:02

标签: python service com powerpoint

我们正在尝试创建一组服务,其中一些服务使用powerpoint。由于我们使用python编写软件代码,因此服务使用COM API连接到powerpoint。基本代码如下:

mutex = win32event.CreateMutex(None, False, 'mutexuniqueid')
if mutex is None:
    raise Exception('Mutex could not be created: %d' % (win32api.GetLastError()))
win32event.WaitForSingleObject(mutex, win32event.INFINITE)
try:
    pythoncom.CoInitializeEx(pythoncom.COINIT_APARTMENTTHREADED)
    try:
        powerpoint = win32com.client.DispatchEx('Powerpoint.Application')
        presentation = powerpoint.Presentations.Open(r'Path\To\Cached\Presentation.ppt', False, True, False)
        # Do whatever necesary with the presentation
        presentation.Close()
        del presentation
finally:
    win32api.CloseHandle(mutex)

如果我们从命令提示符运行程序(基本上是一个rpc服务器),一切都可以正常运行,但是如果我们将程序作为服务安装,它会在powerpoint.Presentations.Open调用期间失败并显示错误:< / p>

(-2147352567, 'Exception occurred.', (0, u'Microsoft PowerPoint 2010', u'PowerPoint could not open the file.', u'', 0, -2147467259), None)

我们已经跟踪问题并且所有COM查询都正确执行,我们在那里有Open函数,所以它在powerpoint内部执行时确实失败了。

有一个问题,我们已经尝试过至少10台计算机,并且它们在每个计算机中都显示了相同的问题,除了一个(恰好是我的)。我们已经检查了这些机器和我自己的机器有什么区别,但到目前为止还没有。

更新 检查不同的计算机后,我们正在管理问题与会话0隔离(会话0中运行的服务)相关的假设。中断的进程似乎也没有登录会话,而正在运行的计算机确实显示了一些登录会话,即使它们也在会话0中运行。

1 个答案:

答案 0 :(得分:1)

所以,似乎此问题发生在此之前,解决方案并不是我预期的原因。完整的答案是here,但基本上,您只需要确定这些文件夹是否存在:

C:\Windows\System32\config\systemprofile\Desktop

C:\Windows\SysWOW64\config\systemprofile\Desktop

还需要阅读和写作的内容。

相关问题