1

I am trying to create a program for a project of mine where I needed to copy some files from my local machine to some remote desktop pc's desktop directory. It is a part of automating the whole connecting and copying files to all the remote PCs. I have used subprocess to connect to a remote desktop. As I am a beginner of using subprocess or cmd commands, I am unable to find a way to do this. This is the code:

from pynput.keyboard import Key,Controller
import time
import subprocess
def process_exists(process_name):
    call = 'TASKLIST', '/FI', 'imagename eq %s' % process_name
    output = subprocess.check_output(call)
    last_line = output.decode("utf-8").strip().split('\r\n')[-1]
    return last_line.lower().startswith(process_name.lower())
#os.system('cmd /k "mstsc /v:192.168.0.107"')
#os.system('cmd /c "notepad"')
from subprocess import Popen
p = Popen('mstsc /v:192.168.0.107')
time.sleep(1)
keyboard = Controller()
# Password is given here
for i in range(10):
    if process_exists('mstsc.exe'):
        time.sleep(1)
        keyboard.type("**********")
        keyboard.press(Key.enter)
        time.sleep(0.12)
        break
time.sleep(3)

Here I used subprocess just to connect to that remote PC. I tried

Popen(r'copy /Y "E:\test.jar" "\\192.168.0.107\c\"')

But it didn't help. Though I didn't know the basic of this line. The error it showed was:

FileNotFoundError: [WinError 2] The system cannot find the file specified

This code is only for test, that's why I used only time delay, didn't check whether it ran correctly. The remote desktop started successfully. But unable to start the copying process.

Sorry for my bad English. Thanks in advance

0 Answers0