Python Forum
help need with running python script on remote windows machine - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: help need with running python script on remote windows machine (/thread-14733.html)



help need with running python script on remote windows machine - onenessboy - Dec-14-2018

Hi all,

I am trying to run below python code for connecting remote windows machine from unix to run an python file exist on that remote windows machine..

Below is the code I am trying:
Code:
#!/usr/bin/env python
import wmi

c = wmi.WMI("xxxxx", user="xxxx", password="xxxxxxx")
process_startup = c.Win32_ProcessStartup.new()
process_id, result = c.Win32_Process.Create(CommandLine="C:\Python27\abtest.py")
if result == 0:
  print("Process started successfully: %d" % process_id)
print(result)
connection is established successfully. But its not executing the python script..
if i had to do it manually then on remote i will got c:\phhton27 manually then run at prompt like below
c:/python27> python abtest.py
How can I put above command in .Win32_Process.Create format.

please guide..


RE: help need with running python script on remote windows machine - jeanMichelBain - Dec-14-2018

My understanding of wmi is you cannot use it on linux, because it's a wrapper on a windows dll.
One way I see is to install cygwin, by this way you will have a linux emulation on your windows pc, et so you could be able to run a ssh server and eventually run python. Dirty, heavy, long, if it works.
May be openssh will give you a way to start a ssh server, good luck also to test it.
Another way, probably the best, is to start a python server process on windows (for instance, see : https://docs.python.org/fr/3/library/wsgiref.html#module-wsgiref), which can start other processes. It can be done by many ways, it depends of what you want. Tell us more.

Apologize, some package claims they are able to do wmi from linux.
But I didn't see them in the official packages, so take care of what they are and what they do exactly...
I wouldn't test it on own pc...


RE: help need with running python script on remote windows machine - onenessboy - Dec-14-2018

hmm. yeah saw some google post wmi , the above code taken from that reference only... its not executing intended file