kj7ny wrote: > How do I enable/disable a scheduled task using Python? > > I can get to a task: > > self.ts=pythoncom.CoCreateInstance > (taskscheduler.CLSID_CTaskScheduler,None,pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler) > self.ts.SetTargetComputer(u'\\\\SomeServer') > self.tasks=self.ts.Enum() > for task in self.tasks: > self.t=self.ts.Activate(task) > if self.t.GetAccountInformation().lower().find('SomeUser') >>=0: > print self.t.GetFlags() > > I can find if a task is enabled or not and toggle it: > > disabled=self.t.GetFlags() & > taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED > print 'Originally Disabled: %s'%(disabled,) > if disabled: > self.t.SetFlags(self.t.GetFlags() & > ~taskscheduler.TASK_FLAG_DISABLED) > else: > self.t.SetFlags(self.t.GetFlags() | > taskscheduler.TASK_FLAG_DISABLED) > disabled=self.t.GetFlags() & > taskscheduler.TASK_FLAG_DISABLED == taskscheduler.TASK_FLAG_DISABLED > print 'Recheck Disabled: %s'%(disabled,) > > ... "Recheck Disabled" shows that the value "says" it has been > disabled. > > The problem is that if I run it again and again, "Originally Disabled" > is always the same. In other words, "Recheck Disabled" does NOT > stick. It's like I'm missing a .commit() >
Your missing commit is spelled pf=t.QueryInterface(pythoncom.IID_IPersistFile) pf.Save(None,1) Roger -- http://mail.python.org/mailman/listinfo/python-list