How to Automatically Run Batch Files on Shutdown Using Windows Task Scheduler
Following the previous MS Teams account residue issue, this time the goal is to automatically run a batch file on every shutdown or startup to delete accounts, which can be achieved using Windows Task Scheduler. Below are the detailed steps for the setup:
1. Open Task Scheduler
Press Win + R, type taskschd.msc, and press Enter. This will open the Windows Task Scheduler.
2. Create a New Task
In the right panel of Task Scheduler, click “Create Task”. Create an advanced task and configure more options. Do not use a basic task, as it does not allow detailed configurations, such as steps 3 and 6, which are unavailable in a basic task.
3. Configure General Options
-
- In the General tab, give the task a name and description.
- Check “Run whether user is logged on or not” to ensure the task runs even if no user is logged in.
- Check “Run with highest privileges” to ensure the task has sufficient rights to run the batch file.
4. Set Trigger Conditions
-
- Go to the Triggers tab and click “New”.
- In the “Begin the task” dropdown, select “On an event”.
- In the “Log”, select “System”, and in the “Source”, choose “User32”, then set the Event ID to 1074. This Event ID indicates the task will be triggered during shutdown or restart.
5. Configure Action
6. Set Conditions
-
- Go to the Conditions tab and uncheck “Start the task only if the computer is on AC power”. This ensures that the task will run even if the computer is on battery mode. Other conditions are up to your needs.
7. Set Other Options
-
- Go to the Settings tab and make sure to check “Allow task to run on demand”. This guarantees that the task will run as expected whenever needed.
8. Save and Test
Once you have completed the above setup, click “OK” to save the task. You may be prompted to enter an administrator password to confirm the changes.
Test the Task: Try shutting down the computer and ensure the batch file runs automatically at shutdown. If configured correctly, the task will run and execute the batch file during system shutdown. You may see an error message when starting up again, but it can be ignored, as Teams will continue to work normally.
FAQ
- What should I do if the batch file does not execute during shutdown?
- Ensure that the Event ID (1074) is set correctly and that “Run with highest privileges” is checked.
- Check the batch file path to make sure it is correct, and ensure the file itself is error-free.
- Check the task history for any system error messages that may help debug the issue.








