Help [robocopy script]

i try this script to run robocopy command and copy the user desktop to shared folder on network
the problem is robocopy shoud run as administrator so when i run it message show to enter administrator password


import os
import smtplib
import getpass
import subprocess
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders
#get user name
usrnm = getpass.getuser()
#create folder on network
file_path= "\\\\10.0.0.181\\companyfiles"
dirctory_path =file_path+"\\"+usrnm
#check if dirctory does not exist
if not os.path.exists(dirctory_path):
    os.makedirs(dirctory_path)

#Deskktop Start
source1 = "C:\\users\\" + usrnm + "\\Desktop\\ "
dest1 = dirctory_path + "\\Desktop\\ "
cmd1 = "robocopy " +source1 + dest1 +" /E /XA:H /W:0 /R:1 /REG /FFT /E >> C:\\"+usrnm+"desktopbackup.log"
subprocess.call(['runas', '/user:Administrator', cmd1 ])
#os.system(cmd1)
print (cmd1)
print("doen")
#os.system(cmd1)
#desktopEnd
#send email with log


so can you fix it or can you make script to differential backup for desktop , documents with sending email with log file

Thanks

Did you run the script as the system user??

Hi @BOSS
i need to run as logged user because in this script i need to backup desktop + document for logged user so i used getuser() function to know which file should copy for example
c:\users\username\desktop
Thanks

It would seem that this line

subprocess.call([‘runas’, ‘/user:Administrator’, cmd1 ])
is wanting to run as the Administrator, this seems to be unlikely to work, unless the user has admin access. In my mind, this is why you would need to run it as the system user, or give the logged on user admin access. Other wise, you could try to comment out that line and rerun, or pass admin account info in the script, but I wouldn’t suggest hard coding admin credentials into anything.