我正在尝试使用ITASKDEFINITION 获取计划任务的“下一个运行时间”,但是在获取“ NextRunTime”时遇到了麻烦,我遇到了错误
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
这是示例代码:
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)
对此的任何帮助或帮助,我们将不胜感激。谢谢!