plexpy/lib/win32comext/taskscheduler/test/test_addtask_1.py
dependabot[bot] faef9a94c4
Bump cherrypy from 18.8.0 to 18.9.0 (#2266)
* Bump cherrypy from 18.8.0 to 18.9.0

Bumps [cherrypy](https://github.com/cherrypy/cherrypy) from 18.8.0 to 18.9.0.
- [Changelog](https://github.com/cherrypy/cherrypy/blob/main/CHANGES.rst)
- [Commits](https://github.com/cherrypy/cherrypy/compare/v18.8.0...v18.9.0)

---
updated-dependencies:
- dependency-name: cherrypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update cherrypy==18.9.0

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>

[skip ci]
2024-03-24 15:25:44 -07:00

69 lines
2.1 KiB
Python

import time
import pythoncom
import win32api
from win32com.taskscheduler import taskscheduler
test_task_name = "test_addtask_1.job"
ts = pythoncom.CoCreateInstance(
taskscheduler.CLSID_CTaskScheduler,
None,
pythoncom.CLSCTX_INPROC_SERVER,
taskscheduler.IID_ITaskScheduler,
)
tasks = ts.Enum()
for task in tasks:
print(task)
if test_task_name in tasks:
print("Deleting existing task " + test_task_name)
ts.Delete(test_task_name)
new_task = pythoncom.CoCreateInstance(
taskscheduler.CLSID_CTask,
None,
pythoncom.CLSCTX_INPROC_SERVER,
taskscheduler.IID_ITask,
)
ts.AddWorkItem(test_task_name, new_task) ## task object is modified in place
new_task.SetFlags(
taskscheduler.TASK_FLAG_INTERACTIVE | taskscheduler.TASK_FLAG_RUN_ONLY_IF_LOGGED_ON
)
new_task.SetIdleWait(1, 10000)
new_task.SetComment("test task with idle trigger")
new_task.SetApplicationName("c:\\python23\\python.exe")
new_task.SetPriority(taskscheduler.REALTIME_PRIORITY_CLASS)
new_task.SetParameters(
"-c\"import win32ui,time;win32ui.MessageBox('why aint you doing no work ?');\""
)
new_task.SetWorkingDirectory("c:\\python23")
new_task.SetCreator("test_addtask_1.py")
new_task.SetAccountInformation(win32api.GetUserName(), None)
## None is only valid for local system acct or if Flags contain TASK_FLAG_RUN_ONLY_IF_LOGGED_ON
run_time = time.localtime(time.time() + 30)
end_time = time.localtime(time.time() + 60 * 60 * 24)
tr_ind, tr = new_task.CreateTrigger()
tt = tr.GetTrigger()
tt.TriggerType = taskscheduler.TASK_EVENT_TRIGGER_ON_IDLE
tt.Flags = taskscheduler.TASK_TRIGGER_FLAG_HAS_END_DATE
tt.BeginYear = int(time.strftime("%Y", run_time))
tt.BeginMonth = int(time.strftime("%m", run_time))
tt.BeginDay = int(time.strftime("%d", run_time))
tt.StartMinute = int(time.strftime("%M", run_time))
tt.StartHour = int(time.strftime("%H", run_time))
tt.EndYear = int(time.strftime("%Y", end_time))
tt.EndMonth = int(time.strftime("%m", end_time))
tt.EndDay = int(time.strftime("%d", end_time))
tr.SetTrigger(tt)
print(new_task.GetTriggerString(tr_ind))
pf = new_task.QueryInterface(pythoncom.IID_IPersistFile)
pf.Save(None, 1)