日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python 任务计划_使用Python添加计划任务

發布時間:2025/3/15 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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添加计划任务的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。