Skip to main content

Python pywin32 Windows Task Scheduler wrapper

Project description

tsksch

A python pywin32 wrapper library for Windows Task Scheduler.

List All Scheduled Tasks
from tasksch.scheduler import TaskService


with TaskService() as ts:
    root = ts.root_folder() 
    for folder in root.walk():
        print(f"DIR: {folder.path}")
        for task in folder.tasks():
            print(f"TSK: {task.path}") 
Create New Folder
from tasksch.scheduler import TaskService

with TaskService() as ts:
    root = ts.root_folder()
    if not root.find("\\NEW FOLDER"):
        root.create_folder("\\NEW FOLDER")
Create New Task
from tasksch folder import TaskFolder
from tasksch.scheduler import TaskService
from tasksch.com import local_datetime
from tasksch.settings import duration, TaskInstancesPolicy
from tasksch.principle import TaskRunlevelType


with TaskService() as ts:
    root = ts.root_folder()

    folder = root.find(folder_name)
    if not folder:
        return

    existing_task = folder.find_task(task_name)
    if existing_task:
        return

    task = service.new_task()

    reg_info = task.registration_info
    reg_info.author = 'Mark Gemmill'
    reg_info.description = 'Test Task'

    action = task.actions.create_exec_action()
    action.path = r"C:\Users\username\execute.bat"
    action.working_directory = r"C:\Users\username"

    trigger = task.triggers.create_daily_trigger()
    trigger.start_boundary = local_datetime(2024, 1, 1, 5, 30) 
    trigger.days_interval = 1
    trigger.enabled = True

    settings = task.settings
    settings.enabled = True
    settings.hidden = True
    settings.multiple_instances = TaskInstancesPolicy.TASK_INSTANCES_IGNORE_NEW 
    settings.allow_demand_start = True
    settings.execution_time_limit = duration(hours=1, minutes=30)

    principal = task.principal
    principal.user_id = 'mark'
    principal.run_level = TaskRunlevelType.TASK_RUNLEVEL_HIGHEST

    folder.register_new_task_definition(
        task, 
        task_name, 
        'username',
        'Ckr1t',
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tasksch-0.2.0.tar.gz (11.1 kB view details)

Uploaded Source

File details

Details for the file tasksch-0.2.0.tar.gz.

File metadata

  • Download URL: tasksch-0.2.0.tar.gz
  • Upload date:
  • Size: 11.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.10.6 Darwin/23.6.0

File hashes

Hashes for tasksch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 62419970c1b078f3197e2e8994e113668f5ccd6a5dd2d6e7149a98a587476d4c
MD5 8d41ebabf1cbf58fb5a0e9b608946196
BLAKE2b-256 ac329e5df2b1b6ff4d92323a6e413b5a46d997c186ac4e8b435638f6a01a9bb6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page