Tips and Tools to Automate Repetitive Tasks on Windows 10
Do you often find yourself deleting old files, cleaning the unrequired data, starting some programs, etc. manually? If it’s yes, then let me help you automate and do more in less time. Though these automations don’t save much time, but weighing the need of the time, any amount of time saved is worth trying.
I’ll start by introducing you to few Windows tools that help us in automating certain tasks, and then I’ll show you some examples of me automating tasks on my Windows 10 PC.
Read Also: How to Disable Windows 10 Automatic Maintenance
Tools you must know
Maybe you’ve already heard of these tools — Command Prompt, PowerShell, and Task Scheduler. If not, not to 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. And a file having multiple of its commands is known as a “batch file”, which you can use to automate tasks, e.g., to backup a file or folder to a portable drive. If you wish to try it out, type “cmd” or “Command Prompt” in Start menu’s search bar, and you’ll find it.
You just need to compile the required commands in a text file having “.bat” or “.cmd” extension. And you can simply open the file to run it; in this case, Windows 10 executes all the file’s commands sequentially or as programmed in the batch file.
List of commands | How to use
PowerShell and its script files
PowerShell is an automation and management framework built for power users aka system admins. If you’re looking for true automation potential, then you need to learn and use PowerShell.
I must tell you that Command Prompt is much easier to learn and use than PowerShell because the latter offers lot more power and features than the former.
You can access Windows PowerShell by typing its name in the Start menu’s search box. Do note that you’ll see two programs — “PowerShell” and “PowerShell ISE”. PowerShell is the command-line interpreter program like Command Prompt whereas the other is used to write scripts (having “.ps1” extension), which contain a group of commands like batch files.
List of commands | How to use | More info
Task Scheduler and its tasks
Another Windows tool that helps in automation is Task Scheduler — a program to schedule programs and tasks. The scheduled tasks run at specific time intervals, can display messages or notifications to show when the tasks are complete, and a lot more. Moreover, you can customize the tasks to suit your requirements.
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. Do note that even Windows and various installed programs (like Google Chrome) create scheduled tasks to do their own maintenance activities, so please don’t edit or disable other tasks.
How to use | More info
Let’s automate tasks
Now that you know about the required tools, let’s create some magical scripts and tasks. These scripts cum tasks, if configured properly, can automate various maintenance tasks on your computer without the need of you checking or intervening in these activities.
Start multiple apps
If you find it slow to open multiple required files on every startup, then you can automate it like I did. Just identify some 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 this shortcut to launch it quickly using the shortcut keys.
For instance, you can create a batch file to open few specific folders, Google Chrome browser, a Word file, and an Excel file using code below. Do note that “%USERPROFILE%” in the below refers to your user profile’s directory in Windows.
@echo off :: Open folders start %USERPROFILE%Documents start %USERPROFILE%DesktopMusicFolder :: Open files start chrome.exe start "" "%USERPROFILE%DocumentsMy BlogsArticle1.docx" start "" "%USERPROFILE%DocumentsContent Ideas.xlsx" exit
Start apps as admin
You must have got success in starting apps using the previous script, but to run a program as an administrator doesn’t work the same way. It’s because the elevated program starts but asks for the admin access by showing a UAC prompt. But if you’re not there to give your approval to the prompt, the program simply exits, i.e., doesn’t starts at all.
The same doesn’t work using a shortcut placed in the Windows Startup folder too. So, how to do it? Task Scheduler program comes to our rescue for this problem. It only 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:
- Open the Task Scheduler > click “Create Task” under Actions in the right panel.
- Under the General tab, add a task name like “NoUAC1”, then check “Run with highest privileges” box.
- Click the Trigger tab, under “Begin the task“, choose “At startup“.
- Now switch to the Actions tab, click New.
- In the New Action window, for Action select “Start a program“, and under Program/script, click Browse button, choose the executable file you wish to schedule and click OK.
- Now head over to the Settings tab > ensure “Allow task to be run on demand” is checked and then click OK to save.
- 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
Being a tech enthusiast and developer, I usually download and test various things, and then after a month or two, I see a host of unneeded files on my system. 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 a subfolder, which are older than the set date and time. Using the code below, one can delete .docx files (change “docx” to match your files) in any specific folder older than twenty days (change the value of “/d” option to set any number of days).
@echo off forfiles /p "%USERPROFILE%DocumentsMy Blogs" /s /m *.docx /d -20 /c "cmd /c del @path" echo Document files older than 20 days deleted pause exit
And you can change the path (by changing the value of “/p” option) to the folder containing the files to be deleted. Below, “%USERPROFILE%” means your user’s directory.
Empty recycle bin
It’s recommended to clear the recycle bin regularly, and though it’s an easy task yet we may often forget it. Thankfully, this can be handled automatically using the Task Scheduler. Here are the steps to auto-optimize the hard drive’s free space:
- Open the Task Scheduler.
- Open up “Task Scheduler Library“, then under Action menu click “New Folder” and name it “My Tasks”.
- Click on “My Tasks” folder, and select “Create Task” from Action menu.
- In the Create Task window under the General tab type the task name as “Empty Windows Recycle Bin”.
- Click Triggers tab, here click New and under “Begin the task” choose “On a schedule“.
- 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.
- Click Actions tab, go to New, and in New Action window, under Settings > for Program/script, type in “PowerShell.exe”.
- In the same window, for “Add arguments (optional)” type
-NoProfile -Command "Clear-RecycleBin -Force"and click OK button.
- That’s all — just save the task, and now the bin will be cleaned on scheduled basis.
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. And that’s where the below script helped me out.
The below-mentioned code will show the message (you can edit it in the script) at 11PM, and turn off the system after 120 seconds (or 2 minutes). Do note that you can even 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 above script to change this duration) to save your work instead of the default 30 seconds. Also, you can stop the shutdown by pressing Win+R > type
shutdown -a > press Enter. It’s pretty easy, right?
Well, I know we have pretty good programs for backing up our files including cloud solutions such as 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, then a batch script is a nice, automated solution. And it’s pretty easy and need no download.
Do 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 make use of 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:UsersUSER :: 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
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 above tools and example scripts, and ease your life a little more.
I know these aren’t all one can achieve using these tools, but you can learn above 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.
Hope you enjoy automating small tasks and improve your productivity too. And don’t forget to share your success story with me at @aksinghnet or using comments.
The post Tips and Tools to Automate Repetitive Tasks on Windows 10 appeared first on Hongkiat.