im trying to automate creation of tasks, i need to create a task scheduler task from cmd with a variable that im getting from the task manager, (im getting a command line of a running process and i need to create a scheduled task) what i did so far:
import psutil
import os
for proc in psutil.process_iter(['pid','name']):
process = proc.info
if process['name'] == 'powershell.exe':
pid = process['pid']
cmd = psutil.Process(pid=int(pid)).cmdline()
for c in cmd:
task = os.system('cmd/k "SCHTASKS /CREATE /SC ONSTART /TN "Tasks\task Runner" /TR {cmd}"'.format(cmd))
i need few things,
- to create from every task manager process command line a task named task runner and if i have few command lines i need to call it task runner2 and so on..
- i need to ignore massages like "the task already exist" and update the tasks
thanks!