1

I would like to use pywin32 API with python running on a remote windows server to operate the Microsoft suite (Outlook etc.) that is located on a local machine (from which I connect to the remote server).

The following code is using the win32com package in order to Dispatch an Outlook application:

import win32com.client as wc
import os

win_local_path = os.path.join(r"\\local_machine", "C")
os.chdir(win_local_path)

outlook = wc.Dispatch("Outlook.Application").GetNamespace("MAPI")

This fails as the win32 client is looking for the Outlook Applications on the server where python is running, not on the local machine where the outlook application lives. There are no issues in locating the local machine with e.g. os.listdir(win_local_path).

Is there any way to tell the pywin32 client to look for the application on the local system?

jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
GinTonic
  • 960
  • 6
  • 10

1 Answers1

1

You need to prepare two Python scripts, one on the remote computer and the other on the local computer.

First, connect to your local machine from the remote computer.

from paramiko.client import SSHClient

client = SSHClient()
client.load_system_host_keys()
client.connect('remote machine ip', username='your_user', password='very_secret')
stdin, stdout, stderr = client.exec_command('python /home/your_user/your/path/to/outlook.py')

Second, the code aboved will execute your local .py code which used to open outlook application.

Third, you just need to save the code written in your question on your local computer.

Refer: Start a process on another computer on the network

Strive Sun
  • 5,988
  • 1
  • 9
  • 26