Here's an example batch file for creating a time-based job using the built-in Windows Task Scheduler:
bash@echo off
rem Set the time to run the task
set "hour=23"
set "minute=30"
rem Set the task name and command to run
set "taskname=My Time-Based Job"
set "command=C:\path\to\my\command.exe"
rem Create the task
schtasks /create /tn "%taskname%" /tr "%command%" /sc daily /st %hour%:%minute%
rem Verify the task was created
schtasks /query /tn "%taskname%"
In this example, the batch file sets the time to run the task to 11:30 PM by setting the hour
and minute
variables. It also sets the name of the task to "My Time-Based Job" and the command to run to "C:\path\to\my\command.exe".
The batch file then uses the schtasks
command to create the task, specifying that it should run daily (/sc daily
) at the specified time (/st %hour%:%minute%
). Finally, it uses the schtasks
command again to verify that the task was created successfully.
Note that the user running the batch file must have administrative privileges in order to create a task using the Task Scheduler. If the command being run requires elevated privileges, you may need to modify the batch file to run it as an administrator.
Comments
Post a Comment