Guide to Automating Tasks on Windows 10 for Better Productivity

Useful tips and tools to help you automate tasks like deleting old files, emptying recycle bin and making a backup of files and folders on Windows 10.

Do you often find yourself deleting old files, cleaning unnecessary data, starting some programs, etc., manually? If so, let me help you automate and achieve more in less time. Although these automations might not save a significant amount of time individually, every bit of time saved can add up and is worth the effort.

I’ll start by introducing you to a few Windows tools that help automate certain tasks. Then, I’ll show you some examples of how I automate tasks on my Windows 10 PC.

How to Disable Windows 10 Automatic Maintenance

How to Disable Windows 10 Automatic Maintenance

One of the most common Windows problems is that your PC becomes sluggish after you leave it idle... Read more

Tools You Should Know

Maybe you’ve already heard of these tools — Command Prompt, PowerShell, and Task Scheduler. If not, don’t worry; let me introduce you to these tools in this section.

Command Prompt and Batch Files

Command Prompt, a successor to MS-DOS Prompt, is a command line interpreter program. A file containing multiple commands for Command Prompt is known as a “batch file,” which you can use to automate tasks, such as backing up a file or folder to a portable drive. To try it out, type “cmd” or “Command Prompt” in the Start menu’s search bar, and you’ll find it.

Command Prompt in Windows 10

You just need to compile the required commands in a text file with a “.bat” or “.cmd” extension. You can then open the file to run it; Windows 10 will execute all the file’s commands sequentially as programmed in the batch file.

List of commands | How to use

PowerShell and Script Files

PowerShell is an automation and management framework built for power users, such as system administrators. If you’re looking for true automation potential, you need to learn and use PowerShell.

Command Prompt is much easier to learn and use than PowerShell because the latter offers many more features and capabilities.

PowerShell in Windows 10

You can access Windows PowerShell by typing its name in the Start menu’s search box. You’ll see two programs — “PowerShell” and “PowerShell ISE”. PowerShell is the command-line interpreter program like Command Prompt, whereas PowerShell ISE is used to write scripts (with a “.ps1” extension) that contain a group of commands like batch files.

List of commands | How to use | More info

20 Windows PowerShell Commands You Must Know

20 Windows PowerShell Commands You Must Know

A list of useful and simple Windows PowerShell commands to help you achieve tasks like getting help or... Read more

Task Scheduler and Tasks

Another Windows tool that helps with automation is Task Scheduler — a program to schedule programs and tasks. The scheduled tasks run at specific time intervals, can display messages or notifications when the tasks are complete, and much more. Moreover, you can customize the tasks to suit your requirements.

Task Scheduler in Windows 10

If you wish to access Task Scheduler in Windows 10, just type “scheduler” or “Task Scheduler” in Cortana’s search box, and you’ll find the scheduler program. Note that even Windows and various installed programs (like Google Chrome) create scheduled tasks to perform their own maintenance activities, so please don’t edit or disable other tasks.

How to use | More info

Automating Tasks

Now that you know about the necessary tools, let’s create some magical scripts and tasks. These scripts, if configured properly, can automate various maintenance tasks on your computer without the need for you to check or intervene in these activities.

Start Multiple Apps

If you find it slow to open multiple required files at every startup, you can automate it like I did. Identify the folders, files, and programs you want to start simultaneously and create a batch file. You can also create a shortcut to this file and add a key combination to launch it quickly using the shortcut keys.

For instance, you can create a batch file to open specific folders, Google Chrome browser, a Word file, and an Excel file using the code below. Note that “%USERPROFILE%” refers to your user profile’s directory in Windows.

@echo off
:: Open folders
start %USERPROFILE%\Documents\
start %USERPROFILE%\Desktop\MusicFolder\
:: Open files
start chrome.exe
start "" "%USERPROFILE%\Documents\My Blogs\Article1.docx"
start "" "%USERPROFILE%\Documents\Content Ideas.xlsx"
exit
Start Apps as Admin

You might have succeeded in starting apps using the previous script, but running a program as an administrator doesn’t work the same way. This is because the elevated program starts but asks for admin access by showing a UAC prompt. If you’re not there to approve the prompt, the program simply exits and doesn’t start at all.

The same approach doesn’t work using a shortcut placed in the Windows Startup folder either. So, how to do it? Task Scheduler comes to our rescue. It features an option to run a program with elevated privileges, so you can start an app or a group of apps (using a batch script) using Task Scheduler. Here’s how to do it:

  1. Open Task Scheduler > click “Create Task” under Actions in the right panel.
  2. Under the General tab, add a task name like “NoUAC1”, then check the “Run with highest privileges” box.
  3. Create a task in Task Scheduler
  4. Click the Trigger tab, under “Begin the task“, choose “At startup“.
  5. Now switch to the Actions tab and click New.
  6. In the New Action window, for Action select “Start a program“, and under Program/script, click the Browse button, choose the executable file you wish to schedule, and click OK.
  7. Set an action in Task Scheduler
  8. Now head over to the Settings tab > ensure “Allow task to be run on demand” is checked and then click OK to save.
  9. That’s all. Now the set program (Adobe Reader per this tutorial) will start automatically with administrative privileges whenever you start the system.
Delete All Old Files

As a tech enthusiast and developer, I often download and test various things, which results in a lot of unneeded files after a month or two. Thankfully, a batch script helps me to delete old downloaded files.

Similarly, you can use a batch file to delete all old files of specific extensions or files in a given folder or subfolder that are older than a set date. Using the code below, you can delete .docx files (change “docx” to match your files) in a specific folder that are older than twenty days (change the value of the “/d” option to set any number of days).

@echo off
forfiles /p "%USERPROFILE%\Documents\My Blogs" /s /m *.docx /d -20 /c "cmd /c del @path"
echo Document files older than 20 days deleted
pause
exit

You can change the path by modifying the value of the “/p” option to the folder containing the files to be deleted. Below, “%USERPROFILE%” refers to your user’s directory.

Delete old files using batch script
Empty Recycle Bin

It’s recommended to clear the recycle bin regularly. Though it’s an easy task, we may often forget to do it. Thankfully, this can be handled automatically using Task Scheduler. Here are the steps to auto-optimize your hard drive’s free space:

  1. Open Task Scheduler.
  2. Open “Task Scheduler Library“, then under the Action menu, click “New Folder” and name it “My Tasks”.
  3. Click on the “My Tasks” folder and select “Create Task” from the Action menu.
  4. In the Create Task window under the General tab, type the task name as “Empty Windows Recycle Bin”.
  5. Click the Triggers tab, then click New and under “Begin the task“, choose “On a schedule“.
  6. Choose the Weekly or Monthly option per your preference, as this will give you enough time to recover/undelete files that you may need, and click OK.
  7. Create trigger to empty recycle bin
  8. Click the Actions tab, go to New, and in the New Action window, under Settings > for Program/script, type “PowerShell.exe”.
  9. In the same window, for “Add arguments (optional)” type -NoProfile -Command "Clear-RecycleBin -Force" and click the OK button.
  10. Use PowerShell to empty recycle bin
  11. That’s all — just save the task, and now the bin will be cleaned on a scheduled basis.
How to Easily Switch Between Tasks on Windows 10

How to Easily Switch Between Tasks on Windows 10

Switching between apps or tasks is something we do often on our computers. Windows 10 gives us many... Read more

Turn Off the System

As I couldn’t stop myself from working late at night, I decided to force myself to abandon the work and go to sleep. The script below helped me achieve that.

The following code will show a message (you can edit it in the script) at 11 PM and turn off the system after 120 seconds (or 2 minutes). Note that you can change the auto shutdown time in the code below by changing the corresponding value of “%time%”.

@echo off
:a
If %time%==23:00:00.00 goto :b
goto :a
:b
shutdown.exe /s /f /t 120 /c "Time To Say Good Night!"
exit

Note: You get 120 seconds (edit “120” in the above script to change this duration) to save your work instead of the default 30 seconds. You can stop the shutdown by pressing Win+R, then type shutdown -a and press Enter. It’s pretty easy, right?

Shut down message after running script
Backup Files/Folders

There are plenty of programs for backing up files, including cloud solutions like Dropbox and Google’s Backup and Sync. However, if you want extreme control and wish to backup extremely sensitive files to your portable hard drive, a batch script is a nice, automated solution. It’s easy and doesn’t require any downloads.

Note that this method just backs up specific files and folders and doesn’t create a standard system restore point or a system backup. I use the “robocopy” command to backup files in this script. Here’s the batch file’s code to backup the complete data inside your user directory and also backup the system registry:

@echo off
:: Set the folder to backup below
set sourcedir=C:\Users\USER
:: Set your portable drive's folder below
set targetdir=D:\Backup
if not exist "%targetdir%" mkdir "%targetdir%"
echo ### Backing up your profile...
robocopy %sourcedir% %targetdir% /e /j /r:10 /v
echo ### Backing up the registry...
if exist "%targetdir%\regbackup.reg" del "%targetdir%\regbackup.reg"
regedit.exe /e "%targetdir%\regbackup.reg"
echo ### Backup is all complete...
pause
exit
folders and registry

Some Concluding Remarks

I’ve always loved automating tasks and processes — that’s why I enjoy using IDEs more than plain text editors. I believe in productivity, and if you do too, then try out the above tools and example scripts to make your life a little easier.

I know these aren’t all you can achieve using these tools, but you can start learning with the provided tools and try out new tricks to automate more tasks. It’s easy to start with these — just follow the links I’ve provided along with the tools in this article, and you’ll be good to go.

WebsiteFacebookTwitterInstagramPinterestLinkedInGoogle+YoutubeRedditDribbbleBehanceGithubCodePenWhatsappEmail