This Markdown README provides an overview and usage guide for the Task Scheduler Python project. The project aims to facilitate the management of Windows scheduled tasks using the win32com.client library. With this project, you can easily create, manage, toggle, run, and delete scheduled tasks programmatically.
Before using the Task Scheduler Python project, make sure you have the required dependencies installed. You can install the necessary packages using the following command:
pip install pywin32To begin using the Task Scheduler, follow these steps:
- Import the
win32com.clientmodule:
importwin32com.client- Create an instance of the
TaskSchedulerclass:
task_scheduler=TaskScheduler()You can create a new scheduled task using the create_task method. Provide the task name, executable path, arguments, and trigger (in ISO 8601 format) as parameters.
task_scheduler.create_task(
task_name="MyTask",
executable_path="C:\\path\\to\\executable.exe",
arguments="--option value",
trigger="2023-08-20T10:00:00"
)Retrieve a list of all tasks with their details using the get_all_tasks method.
all_tasks=task_scheduler.get_all_tasks()
fortaskinall_tasks:
print(task)Toggle the enable/disable state of a task using the toggle_task method.
# Enable the tasktask_scheduler.toggle_task(task_name="MyTask", enable=True)
# Disable the tasktask_scheduler.toggle_task(task_name="MyTask", enable=False)Run a specific task using the run_task method. The task will only run if it is enabled.
task_scheduler.run_task(task_name="MyTask")Delete a scheduled task using the delete_task method.
task_scheduler.delete_task(task_name="MyTask")Here's an example that demonstrates the complete workflow:
importwin32com.client# Create an instance of TaskSchedulertask_scheduler=TaskScheduler()
# Create a new tasktask_scheduler.create_task(
task_name="MyTask",
executable_path="C:\\path\\to\\executable.exe",
arguments="--option value",
trigger="2023-08-20T10:00:00"
)
# Get all tasksall_tasks=task_scheduler.get_all_tasks()
fortaskinall_tasks:
print(task)
# Toggle task statetask_scheduler.toggle_task(task_name="MyTask", enable=True)
# Run the tasktask_scheduler.run_task(task_name="MyTask")
# Delete the tasktask_scheduler.delete_task(task_name="MyTask")The Task Scheduler Python project provides a convenient way to interact with the Windows Task Scheduler using Python and the win32com.client library. You can easily create, manage, toggle, run, and delete scheduled tasks, making task automation a breeze. Explore the methods provided by the TaskScheduler class to customize and enhance your task scheduling workflow.