import win32com.client TASK_ENUM_HIDDEN = 1 TASK_STATE = {0: 'Unknown', 1: 'Disabled', 2: 'Queued', 3: 'Ready', 4: 'Running'} scheduler = win32com.client.Dispatch('Schedule.Service') scheduler.Connect() n = 0 folders = [scheduler.GetFolder('\\rpa')] while folders: folder = folders.pop(0) folders += list(folder.GetFolders(0)) tasks = list(folder.GetTasks(TASK_ENUM_HIDDEN)) n += len(tasks) for task in tasks: print('Task: %s' % task.Definition.Triggers[0].StartBoundary) settings = task.Definition.Settings print('Path : %s' % task.Path) print('Hidden : %s' % settings.Hidden) print('State : %s' % TASK_STATE[task.State]) print('Last Run : %s' % task.LastRunTime) print('Last Result: %s\n' % task.LastTaskResult) print('Last Result: %s\n' % task.GetRunTimes) task.Enabled = True # True表示啟用,False表示停用 task.Run('VT_NULL') status = task.Stop(0) # 0表示立即停止 print('Stop status: %s\n' % status) print('State : %s' % TASK_STATE[task.State]) print('Listed %d tasks.' % n)
标签:folders,task,python,tasks,State,windows,任务,TASK,print From: https://www.cnblogs.com/pythonClub/p/17387105.html