python 任务计划_使用Python添加计划任务
def schtask_com():
'''
Written by Honglei Jiang. Modified from corresponding VB version.
参考资料:
* Advanced Python and COM
http://oreilly.com/catalog/pythonwin32/chapter/ch12.html
* Using the Task Scheduler
http://msdn.microsoft.com/en-us/library/windows/desktop/aa384006(v=VS.85).aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383507(v=VS.85).aspx
* Starting an Executable at a Specific Time
http://msdn.microsoft.com/en-us/library/windows/desktop/aa382152(v=VS.85).aspx
'''
import win32com.client, sys
#A constant that specifies a time-based trigger.
TriggerTypeTime = 1
#A constant that specifies an executable action.
ActionTypeExec = 0
#********************************************************
# Create the TaskService object.
service = win32com.client.Dispatch("Schedule.Service")
service.Connect()
#********************************************************
# Get a folder to create a task definition in.
#Dim rootFolder
rootFolder = service.GetFolder("\\")
taskDefinition = service.NewTask(0)
#Define information about the task.
#Set the registration info for the task by
#creating the RegistrationInfo object.
regInfo = taskDefinition.RegistrationInfo
regInfo.Description = "Start notepad at a certain time"
regInfo.Author = "Author Name"
#********************************************************
# Set the principal for the task
principal = taskDefinition.Principal
# Set the logon type to interactive logon
principal.LogonType = 3
# Set the task setting info for the Task Scheduler by
# creating a TaskSettings object.
#http://msdn.microsoft.com/en-us/library/windows/desktop/aa383480(v=VS.85).aspx
settings = taskDefinition.Settings
settings.Enabled = True #If True, the task is enabled.
settings.StartWhenAvailable = True
settings.Hidden = False #If False, the task will be visible in the UI. The default is False.
settings.MultipleInstances = 0 # Starts a new instance while an existing instance of the task is running.
# settings.RunOnlyIfNetworkAvailable = True
#********************************************************
# Create a time-based trigger.
triggers = taskDefinition.Triggers
trigger = triggers.Create(TriggerTypeTime)
# Trigger variables that define when the trigger is active.
from datetime import datetime
from datetime import timedelta
time = datetime.now() + timedelta(0,30)
startTime = time.strftime('%Y-%m-%dT%H:%M:%S') #YYYY-MM-DDTHH:MM:SS.
#time = DateAdd("s", 30, Now) #start time = 30 seconds from now
#startTime = XmlTime(time)
time = datetime.now() + timedelta(0,5 *30)
endTime = time.strftime('%Y-%m-%dT%H:%M:%S')
#time = DateAdd("n", 5, Now) #end time = 5 minutes from now
#endTime = XmlTime(time)
print "startTime :" , startTime
print "endTime :" , endTime
trigger.StartBoundary = startTime
trigger.EndBoundary = endTime
trigger.ExecutionTimeLimit = "PT5M" #Five minutes
trigger.Id = "TimeTriggerId"
trigger.Enabled = True
#***********************************************************
# Create the action for the task to execute.
# Add an action to the task to run notepad.exe.
Action = taskDefinition.Actions.Create( ActionTypeExec )
Action.Path = "C:\\Windows\\System32\\notepad.exe"
print "Task definition created. About to submit the task..."
#***********************************************************
# Register (create) the task.
'''
参考 http://msdn.microsoft.com/en-us/library/windows/desktop/aa382577(v=VS.85).aspx
TaskFolder.RegisterTaskDefinition( _
ByVal path, # The name of the task.
ByVal definition, # The definition of the task that is registered.
ByVal flags, _ #0x6 TASK_CREATE_OR_UPDATE
ByVal userId, _
ByVal password, _
ByVal longonType, #3 User must already be logged on. The task will be run only in an existing interactive session.
[ ByVal sddl ], _
ByRef task _
)
'''
#
rootFolder.RegisterTaskDefinition( "Test TimeTrigger", taskDefinition, 6, None,None , 3)
print "Task submitted."
python 任务计划_使用Python添加计划任务相关推荐
- python 时间序列预测_使用Python进行动手时间序列预测
python 时间序列预测 Time series analysis is the endeavor of extracting meaningful summary and statistical ...
- python 概率分布模型_使用python的概率模型进行公司估值
python 概率分布模型 Note from Towards Data Science's editors: While we allow independent authors to publis ...
- 使用python预测基金_使用python先知3 1创建预测
使用python预测基金 This tutorial was created to democratize data science for business users (i.e., minimiz ...
- python最佳编程_学习 Python 的最佳方式
原标题:学习 Python 的最佳方式 Python 是世界上功能最多且最强大的编程语言之一.使用 Python,你可以编写自己的应用程序,创建游戏.设计算法.甚至编程一个机器人.学习 Python ...
- python queue 调试_学Python不是盲目的,是有做过功课认真去了解的
有多少伙伴是因为一句'人生苦短,我用Python'萌生想法学Python的!我跟大家更新过很多Python学习教程普及过多次的Python相关知识,不过大家还是还得计划一下Python学习路线!Pyt ...
- python 网页编程_通过Python编程检索网页
python 网页编程 The internet and the World Wide Web (WWW), is probably the most prominent source of info ...
- python 查询包_查找Python包的依赖包(语句)
Window 10家庭中文版,Python 3.6.4, 今天看完了urllib3的官文(官方文档),因为没有具体使用过,所以,仍然是一知半解,但是,突然想知道 urllib3以及前面学习过的requ ...
- python小型编程_学习Python编程的11个资源
用 Python 写代码并不难,事实上,它一直以来都是被声称为最容易学习的编程语言.如果你正打算学习 web 开发,Python 是一个不错的选择,甚至你想学游戏开发也可 以从 Python 开始,因 ...
- python高斯求和_利用Python进行数据分析(3)- 列表、元组、字典、集合
本文主要是对Python的数据结构进行了一个总结,常见的数据结构包含:列表list.元组tuple.字典dict和集合set. image 索引 左边0开始,右边-1开始 通过index()函数查看索 ...
- python单向认证_使用Python进行单向方差分析的四种方法
python单向认证 The current post will focus on how to carry out between-subjects ANOVA using Python. As m ...
最新文章
- 第二百九十、一、二天 how can I 坚持
- 开始使用 Markdown
- Hadoop HIVE 条件控制函数
- Android 封装handler,Android 异步通信原理机制-- handler
- JavaScript HTML DOM 元素(节点)
- python中punctuation_Python中的字符串
- HTML页面跳转的5种方法分析介绍
- NC65新增按钮、新增按钮拦截器,某个字段制作超链接
- 实战Kaggle比赛(二)——房价预测
- 阿里云飞天计划ECS使用体验
- 报告解读下载 | 7月《中国数据库行业分析报告》重磅发布!精彩抢先看!
- 倾斜摄影超大场景的三维模型的顶层合并的优势浅析
- MySQL—关联查询与子查询(从小白到大牛)
- SQL进阶教程 | 史上最易懂SQL教程!10小时零基础成长SQL大师!!
- python日历类_Python 时间日历类型
- 如何给word 文章的每段段尾添加 脚注
- Shell编程学习(四)read读取、函数、文件归档、定时任务
- android资源的诡异问题
- win系统录音设备无法正常录音解决方案之一
- (笔记)双重差分(DID)、拓展及其Stata实现