I'm having trouble executing part of a python (converting a PPTx to PDF, either with win32com or with comtypes):
obj = win32com.client.Dispatch('Powerpoint.Application')
obj.Visible = 1
doc = obj.Presentations.Open(file_name_ptx)
doc.SaveAs(file_name_pdf, FileFormat=32)
The python works perfectly if I run it from CMD, or even within sublime or equivalent. It also works if I run it through a window scheduled task.
However, it fails if it is run through another script, for example from another subprocessed python (either with POpen or with Run) or from php (using cmd_exe).
It also fails if that script is executed through a "remote" request (from another PC).
The failure always occurs in the same place, the script is not able to open the PPTx application:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 81, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operacixf3n no disponible', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "*******.PY", line 706, in
obj = win32com.client.Dispatch('Powerpoint.Application')
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\ProgramData\Anaconda3\lib\site-packages\win32com\client\dynamic.py", line 83, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147023584, 'Una sesixf3n de inicio especificada no existe. Es posible que haya finalizado.', None, None)
I have been looking for various solutions, I have tried with different modules, I have even tried to create a PowerShell file that converts PowerPoint to PDF and the exact same thing happens, if I run the PS1 from CMD it works perfectly, but if I run it remotely or through from another script, it fails for the exact same reason, it is unable to open an instance of PowerPoint.
I have also tried, remotely, to first activate the windows GUI (deactivate the user lock screen and access as if it were a real person) and then execute any script (PY, PS1, etc.), but still with the desktop properly open and without user lock screen the script fails at exactly the same point.
Would anyone know what the problem is and how to solve it? Thank you.