Batch files, also known as cmd files, are used to execute CMD commands with a pre-programmed file. If you want Windows to perform a certain task, within a certain time, set a schedule to run the Batch file and set a timer to automatically trigger the file to run automatically.
Join the channel Telegram of the AnonyViet 👉 Link 👈 |
Schedule batch file running in Windows with Task Scheduler
For example, you want to set a schedule to confess to batch files or activate virus batch file good to try other cool tricks on CMD. Please follow the instructions below:
After creating a batch file that automates a job, you’ll want it to run automatically at a certain time. The easiest way to do that is to use the Task Scheduler built into Windows. This is a tool that automatically runs a pre-scheduled job.
- Select Start menu and enter scheduler. The first result that appears will be Windows Task Scheduler.
Task Scheduler will have many pre-scheduled tasks. Windows and other programs also use scheduled tasks.
- Create a new folder for your tasks for easy identification. Right click on Task Scheduler Library and choose New Folder… or choose New Folder in the table Actions on the right side.
- Enter a name for the new folder. Naming has a little meaning.
- Right click on the new folder and select Create Task… or choose Create Task… in the table Actions.
- Windows Create Task will open tab General. Enter a meaningful name for the task in Name. In the section Description, write the task that this task does.
Note the button Change User or Group. It will allow you to run the script under a different user. If your batch file requires Administrator rights, you should change the user to Administrator. It will ask you to enter the Administrator’s password.Also, note that the script will only run when the user is logged in (Run only when the user is logged on). You can change this setting to Run whether the user is logged in or not (Run whether user is logged on or not) if you want it to run at any time.
- Select tab Triggers (activated). Triggers is what determines when a task runs. Select new to create triggers.
- There are many options in the window New Trigger. You can see what those options are.
- In the section Begin the tasks Includes options:
– On a schedule
– At log on (At login)
– At startup (At startup)
– On idle
– On an event (When an event occurs)
– At task creation/modification (At task creation/modification)
– On connection to user session (When connecting to user session)
– On disconnect from user session (When disconnecting from user session)
– On workstation lock (On locked machine)
– On workstation unlock (On unlocked machine)
On a schedule is the most common way and the one that I will use in this article. - There are also options for scheduling Settings. Options include:
– One time (once)
– Daily (daily)
– Weekly (weekly)
– Monthly (monthly)
I will choose Daily for this example. - In Advanced settings, you can customize more parameters about how the task fires. This action is currently set to repeat every 5 minutes, indefinitely. Note that the box Enabled is selected by default. This is the first place to check when troubleshooting why a scheduled task isn’t running. Select OK when you’re done setting up.
- Select tab Actionsthen select new to indicate what the scheduled task will do.
- In the menu Action: you have the following options:
– Start a program
– Send an email
– Display a message.
The last two options are not supported anymore. It’s best not to use them when you’re scheduling batch files. Leave it as default Start a program.Enter the full path to the script. Press Browse and select that command file.
Items Add arguments and Start in fields will be empty. You can use them when moving to more complex scripts and tasks. You will definitely need these to schedule PowerShell scripts. Select OK to continue. - The task is scheduled. Select OK to close the window and return to the Task Scheduler. Select the task you just created and test it. Right click on the task and select Run or choose Run in the table Actions.
When the quest is over, look at the column Last Run Result. You will see the text The operation completed successfully.
If it shows differently, try pressing the F5 button to refresh the screen. If it still says otherwise, the task you created probably failed.
Learn about the Conditions and Settings tab?
There are two tabs that we did not discuss in the tutorial above. For most tasks, you don’t need to dig into these tabs. However, we still have to see what they contain.
Create Task – Conditions
These settings are related to the state of the computer. If the task takes up a lot of resources or can interrupt the person using it, change the Idle.
Part Power By default, only Start Task if the computer is on AC power (Start the task only if the computer is on AC power) and Stop if the computer switches to battery power (Stop if the computer switches to battery power) is enabled.
In most cases when you schedule batch files, you should be fine with the above options. I put some computers to sleep to save power when they are not in use. But if the computer is in sleep mode, the task will not run. If that’s the case, you’ll need to check the dialog box Wake the computer to run this task.
Today, computers are almost always connected to the network. However, if your task depends on a network connection, change the Network.
Create Task – Settings
Tab Settings related to the operation of the task. By default, the Allow task runs on demand ( Allow task to be run on demand).
Some tasks may get stuck in a loop or not run because their trigger conditions are not met. These are the settings you will have to adjust to solve that problem. For most tasks, default settings are best.