Advertisement
Guest User

Untitled

a guest
May 3rd, 2010
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import pythoncom
  2. import win32api
  3. from win32com.taskscheduler import taskscheduler
  4. import lib.utils as utils
  5. import time
  6. schd = pythoncom.CoCreateInstance(taskscheduler.CLSID_CTaskScheduler, None, pythoncom.CLSCTX_INPROC_SERVER,taskscheduler.IID_ITaskScheduler)
  7. schd.NewWorkItem("Test")
  8. job =schd.NewWorkItem("Test")
  9. job.SetApplicationName("notepad.exe")
  10. job.SetComment("test")
  11. job.SetPriority(taskscheduler.NORMAL_PRIORITY_CLASS)
  12. job.SetFlags(taskscheduler.TASK_FLAG_DELETE_WHEN_DONE|taskscheduler.TASK_FLAG_DONT_START_IF_ON_BATTERIES|taskscheduler.TASK_FLAG_RUN_IF_CONNECTED_TO_INTERNET)
  13. job.SetAccountInformation("user", "password")
  14. schd.AddWorkItem("Test", job)
  15. run_time = time.localtime(time.time() + 100)
  16. run_time = time.localtime(time.time() + 100)
  17. tr_ind, tr = job.CreateTrigger()
  18. run_time = time.localtime(time.time() + 50000)
  19. tt = tr.GetTrigger()
  20. tt.Flags=0
  21. tt.BeginYear = int(time.strftime('%Y', run_time))
  22. tt.BeginMonth = int(time.strftime('%m', run_time))
  23. tt.BeginDay = int(time.strftime('%d', run_time))
  24. tt.StartHour = int(time.strftime('%H', run_time))
  25. tt.StartMinute = int(time.strftime('%M', run_time))
  26. trigger_type_flags = taskscheduler.TASK_TIME_TRIGGER_DAILY
  27. tt.TriggerType = int(trigger_type_flags)
  28. tr.SetTrigger(tt)
  29. # ^^^ this should have worked
  30. pf = job.QueryInterface(pythoncom.IID_IPersistFile)
  31. pf.Save(None,1)
  32. job = schd.Activate("Test")
  33. exit_code, startup_error_code = job.GetExitCode()
  34. # job.Run() works
  35. # the task is created without any trigger
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement