mirror of
https://github.com/aykhans/AzSuicideDataVisualization.git
synced 2025-07-02 22:30:48 +00:00
first commit
This commit is contained in:
@ -0,0 +1,61 @@
|
||||
import pythoncom, sys, os, time, win32api
|
||||
from win32com.taskscheduler import taskscheduler
|
||||
|
||||
task_name = "test_addtask.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 task_name in tasks:
|
||||
print("Deleting existing task " + task_name)
|
||||
ts.Delete(task_name)
|
||||
|
||||
t = ts.NewWorkItem(task_name)
|
||||
t.SetComment("rude comments")
|
||||
t.SetApplicationName(sys.executable)
|
||||
t.SetPriority(taskscheduler.REALTIME_PRIORITY_CLASS)
|
||||
t.SetParameters(
|
||||
"-c\"import win32ui,time;win32ui.MessageBox('hey bubba I am running');\""
|
||||
)
|
||||
t.SetWorkingDirectory(os.path.dirname(sys.executable))
|
||||
t.SetCreator("test_addtask.py")
|
||||
t.SetMaxRunTime(20000) # milliseconds
|
||||
t.SetFlags(
|
||||
taskscheduler.TASK_FLAG_INTERACTIVE | taskscheduler.TASK_FLAG_RUN_ONLY_IF_LOGGED_ON
|
||||
)
|
||||
## |taskscheduler.TASK_FLAG_DELETE_WHEN_DONE) #task self destructs when no more future run times
|
||||
t.SetAccountInformation(win32api.GetUserName(), None)
|
||||
## None is only valid for local system acct or if task flags contain TASK_FLAG_RUN_ONLY_IF_LOGGED_ON
|
||||
t.SetWorkItemData("some binary garbage")
|
||||
|
||||
run_time = time.localtime(time.time() + 60)
|
||||
tr_ind, tr = t.CreateTrigger()
|
||||
tt = tr.GetTrigger()
|
||||
|
||||
## flags default to TASK_TRIGGER_FLAG_DISABLED (4)
|
||||
tt.Flags = taskscheduler.TASK_TRIGGER_FLAG_KILL_AT_DURATION_END
|
||||
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.MinutesInterval = 1
|
||||
tt.MinutesDuration = 5
|
||||
|
||||
tt.TriggerType = taskscheduler.TASK_TIME_TRIGGER_MONTHLYDATE
|
||||
# months can contain multiples in a bitmask, use 1<<(month_nbr-1)
|
||||
tt.MonthlyDate_Months = 1 << (
|
||||
int(time.strftime("%m", run_time)) - 1
|
||||
) ## corresponds to TASK_JANUARY..TASK_DECEMBER constants
|
||||
# days too
|
||||
tt.MonthlyDate_Days = 1 << (int(time.strftime("%d", run_time)) - 1)
|
||||
tr.SetTrigger(tt)
|
||||
print(t.GetTriggerString(tr_ind))
|
||||
|
||||
pf = t.QueryInterface(pythoncom.IID_IPersistFile)
|
||||
pf.Save(None, 1)
|
@ -0,0 +1,66 @@
|
||||
import pythoncom, time, 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)
|
@ -0,0 +1,48 @@
|
||||
import pythoncom, time, win32api
|
||||
from win32com.taskscheduler import taskscheduler
|
||||
|
||||
task_name = "test_addtask_2.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 task_name in tasks:
|
||||
print("Deleting existing task " + task_name)
|
||||
ts.Delete(task_name)
|
||||
|
||||
t = ts.NewWorkItem(task_name)
|
||||
t.SetComment("Test a task running as local system acct")
|
||||
t.SetApplicationName("c:\\python23\\python.exe")
|
||||
t.SetPriority(taskscheduler.REALTIME_PRIORITY_CLASS)
|
||||
t.SetParameters("test_localsystem.py")
|
||||
t.SetWorkingDirectory("c:\\python23")
|
||||
t.SetCreator("test_addtask_2.py")
|
||||
t.SetMaxRunTime(20000) # milliseconds
|
||||
t.SetFlags(taskscheduler.TASK_FLAG_DELETE_WHEN_DONE)
|
||||
t.SetAccountInformation(
|
||||
"", None
|
||||
) ## empty string for account name means to use local system
|
||||
## None is only valid for local system acct or if task flags contain TASK_FLAG_RUN_ONLY_IF_LOGGED_ON
|
||||
|
||||
run_time = time.localtime(time.time() + 60)
|
||||
tr_ind, tr = t.CreateTrigger()
|
||||
|
||||
tt = tr.GetTrigger()
|
||||
tt.Flags = 0 ## flags for a new trigger default to TASK_TRIGGER_FLAG_DISABLED (4), make sure to clear them if not using any
|
||||
tt.TriggerType = taskscheduler.TASK_TIME_TRIGGER_ONCE
|
||||
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))
|
||||
|
||||
tr.SetTrigger(tt)
|
||||
print(t.GetTriggerString(tr_ind))
|
||||
|
||||
pf = t.QueryInterface(pythoncom.IID_IPersistFile)
|
||||
pf.Save(None, 1)
|
@ -0,0 +1,3 @@
|
||||
f = open("test_localsystem.txt", "w")
|
||||
f.write("I have run\n")
|
||||
f.close()
|
Reference in New Issue
Block a user