{"id":28394366,"url":"https://github.com/maximilianfeldthusen/scheduledtask","last_synced_at":"2026-05-03T07:42:49.390Z","repository":{"id":289709545,"uuid":"967905148","full_name":"maximilianfeldthusen/ScheduledTask","owner":"maximilianfeldthusen","description":"The code sets up a scheduled task in Windows that runs a specified executable whenever a user logs on. It utilizes the Windows Taskcheduler API and COM interfaces to achieve this.","archived":false,"fork":false,"pushed_at":"2025-04-24T16:23:30.000Z","size":10,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"TFD","last_synced_at":"2026-05-03T07:42:44.219Z","etag":null,"topics":["api","c","schedule","windows"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maximilianfeldthusen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-17T07:23:59.000Z","updated_at":"2025-09-20T12:19:59.000Z","dependencies_parsed_at":"2025-04-24T17:33:46.141Z","dependency_job_id":"0821147e-4336-4b22-9214-b3ed0e1564c3","html_url":"https://github.com/maximilianfeldthusen/ScheduledTask","commit_stats":null,"previous_names":["maximilianfeldthusen/scheduledtask"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/maximilianfeldthusen/ScheduledTask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FScheduledTask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FScheduledTask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FScheduledTask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FScheduledTask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maximilianfeldthusen","download_url":"https://codeload.github.com/maximilianfeldthusen/ScheduledTask/tar.gz/refs/heads/TFD","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maximilianfeldthusen%2FScheduledTask/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32562118,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-03T06:36:36.687Z","status":"ssl_error","status_checked_at":"2026-05-03T06:36:09.306Z","response_time":103,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","c","schedule","windows"],"created_at":"2025-05-31T18:09:28.599Z","updated_at":"2026-05-03T07:42:49.385Z","avatar_url":"https://github.com/maximilianfeldthusen.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n## Documentation\n\n### ScheduledTask\n\nThe provided code is a C program that creates a scheduled task in Windows using the Task Scheduler API. Below is a detailed explanation of the code's structure and functionality:\n\n### Header Files\n```c\n#include \u003cwindows.h\u003e\n#include \u003cstdio.h\u003e\n#include \u003ctaskschd.h\u003e\n#include \u003ccombaseapi.h\u003e\n```\n- **windows.h**: Provides declarations for the Windows API functions and types.\n- **stdio.h**: For input and output functions (e.g., `printf`).\n- **taskschd.h**: Contains the definitions for the Task Scheduler API.\n- **combaseapi.h**: Provides interfaces for COM (Component Object Model) operations.\n\n### Linking Libraries\n```c\n#pragma comment(lib, \"taskschd.lib\")\n#pragma comment(lib, \"comsupp.lib\")\n```\n- These lines link the necessary libraries for using the Task Scheduler API and COM support.\n\n### Function to Create a Scheduled Task\n```c\nvoid CreateScheduledTask()\n```\nThis function contains the core logic to create the scheduled task.\n\n1. **Initialize COM**:\n    ```c\n    hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);\n    ```\n   - Initializes the COM library for use by the calling thread. It sets the concurrency model to multi-threaded.\n\n2. **Create the Task Service**:\n    ```c\n    hr = CoCreateInstance(\u0026CLSID_TaskScheduler, NULL, CLSCTX_INPROC_SERVER, \u0026IID_ITaskService, (void**)\u0026pService);\n    ```\n   - This line creates an instance of the Task Scheduler service.\n\n3. **Connect to the Task Scheduler Service**:\n    ```c\n    hr = pService-\u003elpVtbl-\u003eConnect(pService, NULL, NULL, NULL, NULL);\n    ```\n   - Establishes a connection to the Task Scheduler service.\n\n4. **Create a New Task Definition**:\n    ```c\n    hr = pService-\u003elpVtbl-\u003eNewTask(pService, 0, \u0026pTask);\n    ```\n   - Creates a new task definition object.\n\n5. **Set Task Registration Info**:\n    ```c\n    hr = pTask-\u003elpVtbl-\u003eget_RegistrationInfo(pTask, \u0026pRegInfo);\n    ```\n   - Retrieves the registration information for the task, which is used to set properties like the task description.\n\n6. **Set Task Principal**:\n    ```c\n    hr = pTask-\u003elpVtbl-\u003eget_Principal(pTask, \u0026pPrincipal);\n    ```\n   - Retrieves the principal object related to the task, which is used to define the security context under which the task runs (e.g., as the local system account).\n\n7. **Create a Trigger**:\n    ```c\n    hr = pTriggerCollection-\u003elpVtbl-\u003eCreate(pTriggerCollection, TriggerType_Logon, \u0026pTrigger);\n    ```\n   - Adds a trigger that specifies when the task should run (in this case, at user logon).\n\n8. **Set Task Action**:\n    ```c\n    hr = pActionCollection-\u003elpVtbl-\u003eCreate(pActionCollection, ActionType_Exec, \u0026pAction);\n    ```\n   - Defines an action that the scheduled task will perform, such as executing a specified program.\n\n9. **Register the Task**:\n    ```c\n    hr = pRootFolder-\u003elpVtbl-\u003eRegisterTaskDefinition(pRootFolder, L\"ExampleTask\", pTask, TASK_CREATE_OR_UPDATE, NULL, NULL, LogonType_ServiceAccount, NULL, NULL);\n    ```\n   - Registers the task under the root folder of the Task Scheduler.\n\n10. **Cleanup**:\n    The function releases all COM objects and uninitializes COM to free resources before returning.\n\n### Main Function\n```c\nint main()\n{\n    CreateScheduledTask();\n    return 0;\n}\n```\n- Calls the `CreateScheduledTask` function to execute the task creation process when the program runs.\n\n### Summary\nThe code sets up a scheduled task in Windows that runs a specified executable whenever a user logs on. It utilizes the Windows Task Scheduler API and COM interfaces to achieve this. Error handling is performed at various steps to ensure that the program can gracefully report issues without crashing. The task is defined to run as the Local System account, which provides sufficient privileges for many tasks.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianfeldthusen%2Fscheduledtask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaximilianfeldthusen%2Fscheduledtask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaximilianfeldthusen%2Fscheduledtask/lists"}