Search code examples
pythonwindowsbatch-filewmi

Run local batch file on remote system with Python WMI


I want to run a local batch file on a remote system with WMI, instead of running a batch file on the remote system. The reason behind this is that I'll need the directory to which I'm referencing in the batch file to be variable, and adjustable by the user. How exactly can I do this? Reference the local file and run it, or send it to the remote sytem? How do I code it either way?

The reason I chose WMI was because it has been extremely reliable thus far, and I have no intention of reusing PsExec, and I have no need for ssh.


Solution

  • Referencing the local file on the remote system is bad because the remote system user has to have access to the file system on your local system which is - viewed by the remote system - a remote system.

    You would have to have a share on your local machine which is accessible from the remote system and modify the batch to access the UNC-Path (pushd).

    The best way would be to copy the batch to the remote system (or create it dynamically on the remote system) and execute it from there.

    • How to create remote processes can be read at this question,
    • several ways to copy files to a remote system are described here