I am new to SO. I am given the task of 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 issues with passing the arguments over to the 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 task is just a test task right now, while I try to figure it out. Also if typed directly into command prompt window, it will work, removing the quotes etc.
In order to schedule the Python script using the Windows Scheduler: Open the Windows Control Panel and then click on the Administrative Tools. Double-click on the Task Scheduler, and then choose the option to 'Create Basic Task…'
Step 1: Open Task Scheduler Application on your Windows Machine. Step 2: Click on 'Create Basic Task…. ' in the Actions Tab. And give a suitable Name and Description of your task that you want to Automate and click on Next.
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 outside and double qoutes inside. Also you can put in the full path to schtasks, if you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With