我正在使用该pythoncom
库以编程方式创建和控制 Windows 任务。xml
在为任务生成下有一个设置Settings
,就是Stop the task if it runs longer than: ...
。我似乎无法在库中找到要更改的设置。我尝试设置,task.SetMaxrunTime(-1)
但是当我在任务属性中查看它时,它似乎并没有禁用此复选框。
这是我到目前为止所做的示例:
import pythoncom
import time
from win32com.taskscheduler import taskscheduler
def create_task(name, cmd, parameters,):
ts = pythoncom.CoCreateInstance(taskscheduler.CLSID_CTaskScheduler,None,
pythoncom.CLSCTX_INPROC_SERVER,
taskscheduler.IID_ITaskScheduler)
ts.Delete(ts.Enum()[0]) # delete it since i am just testing
task = ts.NewWorkItem(name)
task.SetApplicationName(cmd)
task.SetParameters(parameters)
task.SetMaxRunTime(-1)
task.SetPriority(taskscheduler.REALTIME_PRIORITY_CLASS)
#task.SetFlags(taskscheduler.)
task.SetAccountInformation('', None)
ts.AddWorkItem(name, task)
run_time = time.localtime(time.time() + 300)
tr_ind, tr = task.CreateTrigger()
tt = tr.GetTrigger()
tt.Flags = 0
tt.TriggerType = int(taskscheduler.TASK_EVENT_TRIGGER_AT_SYSTEMSTART)
tr.SetTrigger(tt)
pf = task.QueryInterface(pythoncom.IID_IPersistFile)
pf.Save(None,1)
task.Run()
task = ts.Activate(name)
exit_code, startup_error_code = task.GetExitCode()
return win32api.FormatMessage(startup_error_code)
如何Stop the task if it runs longer than: ...
从 python 中取消选中此框?