0

I am trying to get the Next Run Time of a scheduled task using the ITASKDEFINITION but I am having a trouble getting the NextRunTime I am getting the error

Traceback (most recent call last):
  File "WSTC.py", line 34, in <module>
    print('NextRun    : %s\n' % task.NextRunTime)
ValueError: can't format dates this early

Here is the sample code:

import win32com.client

TASK_ENUM_HIDDEN = 0
TASK_STATE = {0: 'Unknown',
              1: 'Disabled',
              2: 'Queued',
              3: 'Ready',
              4: 'Running'}

scheduler = win32com.client.Dispatch('Schedule.Service')
scheduler.Connect()

folders = [scheduler.GetFolder('\\')]
n = 0
while folders:
    folder = folders.pop(0)
    folders += list(folder.GetFolders(0))
    tasks = list(folder.GetTasks(TASK_ENUM_HIDDEN))

    for task in tasks:
        settings = task.Definition.Settings
        if TASK_STATE[task.State] == 'Running':
            print('Path       : %s' % task.Path)
            print('State      : %s' % TASK_STATE[task.State])
            print('NextRun    : %s\n' % task.NextRunTime)
            n += 1
print ('Listed %d tasks.' % n)

Any assistance or help on this greatly appreciated. Thanks!

LearningNoob
  • 662
  • 6
  • 23

1 Answers1

0

After digging deeper and reading about this error. It seems to be that this issue is only in earlier versions of python (I'm using Python 2.7). I tried upgrading python to the latest version and it returns a date lesser than the year 1900 and no longer throws an ValueError exception.

SOURCES: 1 2

LearningNoob
  • 662
  • 6
  • 23