0

For example I have a .py script on my computer (Windows Server 2017), and I want to use it to control a remote server (Windows Server 2017) to do the following steps:

  1. Open MS Word(which has already been installed) on the remote server
  2. Use the word to open a word doc which is located on the remote server too.

Anyone has any brilliant idea? Thanks a lot!

johnhsq
  • 11
  • 2

2 Answers2

0

Soo, for this case, i would prefer PowerShell to do this task, because powershell has a lot of libs for admin taks, and automatization. And powershell are the language used in windows server, in my job, i use powershell to do some taks, like send an email, create a profile in the server, and other things. Show me the code:

$Filename='C:\HappyBirthdayEd.docx' #set the name and location of the file
$Word=NEW-Object –comobject Word.Application #set the word application
$Document=$Word.documents.open($Filename) #open the document

So, this little block of code open an word file. Just do some changes and i thing can work. PS.: Sorry my bad english.

  • It's OK to do it by PowerShell, in this case, however my problem is how to use the PowerShell in my computer to control a remote server, to call a Word.Application which is not in the computer your PowerShell command is based in. – johnhsq Jul 25 '19 at 01:29
  • For the Word.Application a don't know yet, but to control the server you can user Invoke-Command, with Credential and ServerName like this: `Invoke-Command -ComputerName server01 -Credential domain01\user01 -ScriptBlock {Get-Culture}` In the -ScriptBlock you can put the command you have to use. With Invoke-Command you can create sessions in the server, and other things, check the doc here: [link](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/invoke-command?view=powershell-6) – DonnieDarko Jul 25 '19 at 14:48
0

Problem solved here: How to connect to a remote Windows machine to execute commands using python?

johnhsq
  • 11
  • 2