This project is a Rust implementation of the Windows Task Scheduler functionality, specifically focusing on creating tasks that execute when a user logs on. It is based on the Microsoft Windows Task Scheduler Logon Trigger Example.
- Create scheduled tasks that run when a user logs on
- Support for command-line arguments when running tasks
- Dynamically find Task Scheduler GUIDs from the Windows Registry
- Support for custom executable paths
- Automatic cleanup of existing tasks with the same name
- Proper COM initialization and cleanup
- Error handling and reporting
The project uses the following main dependencies:
winapi- For Windows API bindingswinreg- For Windows Registry access
Add the following to your Cargo.toml
[dependencies]
schtask = { git = "https://github.com/Teach2Breach/schtask.git", branch = "main" }Use in your project:
use schtask::create_task;
fn main() {
// Create a task that runs notepad.exe when the user logs on
let result = create_task("MyTask", "C:\\Windows\\System32\\notepad.exe", None);
println!("{}", result);
// Create a task with command-line arguments
let result = create_task(
"MyTaskWithArgs",
"C:\\Windows\\System32\\notepad.exe",
Some("C:\\Windows\\System32\\drivers\\etc\\hosts")
);
println!("{}", result);
}The implementation follows the Windows Task Scheduler COM interface pattern:
- Initialize COM and security settings
- Create an instance of the Task Service
- Get the root task folder
- Create a new task definition
- Configure task settings and registration info
- Add a logon trigger
- Set up the executable action with optional arguments
- Register the task
- The task is created with the current user's credentials
- Tasks are created with interactive token logon type
- The implementation includes proper COM security initialization