test_addtask.py :  » Windows » pyExcelerator » pywin32-214 » com » win32comext » taskscheduler » test » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » com » win32comext » taskscheduler » test » test_addtask.py
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)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.