I am trying to list all scheduled tasks on Windows with a Python script.
On this post, Python check for Completed and failed Task Windows scheduler there is some code which worked.
import win32com.client
TASK_STATE = {0: 'Unknown',
1: 'Disabled',
2: 'Queued',
3: 'Ready',
4: 'Running'}
scheduler = win32com.client.Dispatch('Schedule.Service')
scheduler.Connect()
folders = [scheduler.GetFolder('\\')]
while folders:
folder = folders.pop(0)
folders += list(folder.GetFolders(0))
for task in folder.GetTasks(0):
print('Path : %s' % task.Path)
print('State : %s' % TASK_STATE[task.State])
print('Last Run : %s' % task.LastRunTime)
print('Last Result: %s\n' % task.LastTaskResult)
However, I would like to display the path of the file it executes (e.g. c:\test\aaa.bat
) and the parameters of the command. How could this be done?
And could anyone explain the meaning of some commands in the code:
- [] in the code "[scheduler.GetFolder('\')]"
- Where could I get the detail explaination of code like list(folder.GetFolders(0)), folder.GetTasks(0)? Is there any documentation available?