0

I have a script that re-calculates an Excel file using win32api. It works without errors.

When I try to run the same script remotely through pywinrm, I get an error:

Error: com_error: (-2147352567, 'Exception occurred.', (0, 'Microsoft Excel', "Sorry, we couldn't find test1.xlsm. Is it possible it was moved, renamed or deleted?", 'xlmain11.chm', 0, -2146827284), None)

What can be the problem?

import winrm
host = 'myhost'
domain = 'mydomain'
user = 'myuser'
password = 'mypassword'
session = winrm.Session(host, auth=('{}@{}'.format(user,domain), password), transport='ntlm')

result = session.run_ps('python script.py')

script.py on remote machine

import win32com.client

xlapp = win32com.client.DispatchEx("Excel.Application")
xlapp.Visible = True

path = "C:\\Users\\MyUser\\Desktop\\excel\\test_file.xlsx"
wb = xlapp.Workbooks.open(path)

The file exists on this path. It can be read via open('path', rb). If I run the same code on a remote machine (without winrm, manually), there is no problem.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Petrov
  • 1
  • 2
  • I noticed that client code is most likely copied from https://stackoverflow.com/questions/32324023/how-to-connect-to-remote-machine-via-winrm-in-python-pywinrm-using-domain-acco. Did you also set up the remote machine like in thode answers? – CristiFati Jun 01 '22 at 19:15
  • @CristiFati yes! Another python scripts(without win32com) working without problems – Petrov Jun 02 '22 at 06:16
  • Have you tried adding the user to the group `Distributed COM Users`?https://learn.microsoft.com/en-us/previous-versions/windows/it-pro/windows-server-2012-R2-and-2012/dn579255(v=ws.11)#distributed-com-users – Junjie Zhu - MSFT Jun 03 '22 at 09:57

0 Answers0