Running Windows Task Scheduler via Python

I am new to SO. I have been tasked with creating a Windows Task Schedule to run a .BAT file using our Python API to push it to our fleet of remote PCs.

I am having problems passing arguments to schtask.exe

.

Here is the code:

import subprocess
path = "c:\windows\System32\schtasks.exe"
subprocess.Popen([path, "schtasks /create /SC ONLOGON /TN 'Update_Automation_Beta' /TR 'C:\test\run_admin.bat'"], shell = True)

      

Note. The problem is just a test problem right now while I am trying to figure it out. Also if you typed directly in the command prompt window it will work by removing quotes etc.

+3


source to share


1 answer


This worked for me:

import subprocess
subprocess.call('schtasks /create /SC ONLOGON /TN "Update_Automation_Beta" /TR "C:\test\run_admin.bat"')

      



Use single quotes on the outside and double qoutes on the inside. Also you can put the full path to schtasks if you need.

0


source







All Articles