Many Windows 11/10 users execute similar tasks every day, and while there is a way to execute those tasks every day using the inbuilt Task Scheduler in Windows, its even better if you can execute commands with your voice. This is where Cortana, Microsoft’s Digitial Assistant, comes into the picture.
Cortana can answer questions, launch apps on your PC, and even can execute some pre-defined commands when asked over voice, however, the option to execute custom, and complex commands over voice are not inbuilt into it. In this post, we are looking at various ways you can execute commands hands-free.
This can be achieved simply by asking Cortana to open a script which has some pre-defined commands written into it. Let’s learn how to do it.
Make Cortana execute Commands
If you plan to execute simple commands like Shutdown your PC, Open Settings, Turn off Bluetooth, etc, know that Cortana now supports most of the basic functions on Windows 11/10 PC. You can even launch apps, and games.
Open File Explorer with voice
In this example, I am showing you how to open File Explorer with voice:
- On your desktop, right-click, and select New > Shortcut.
- This will open a prompt which will ask you for Type the location of the item.
- Type in quotes “explorer.exe”, and click next.
- Give a unique name for this. Say “EXP”
- The shortcut will be available on your desktop.
- Now copy it, and navigate to the folder C:\Users\<USERNAME>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs
- Paste it.
One this is done, you can say Hey Cortana, Open EXP, and it will launch Explorer.
It may take some time for Cortana to realize this new shortcut you have in that folder. Cortana indexes programs often, and once done, she can find them.
TIP: Tons of Cortana Tips and Tricks here.
Execute Custom Commands using Cortana
Now let’s say if you have a complex command to execute which is a list of multiple commands to be executed one after the other. Cortana cannot do it, and the shortcut option won’t work either. This is where the role of script come. Imagine this as a set of commands you type on your command prompt one after the other.
You will need to have a basic understanding of commands in Windows. If you are not aware of it, make sure to search on the internet or find somebody who can help you with that.
Scenario: I copy files every day from one of my drive to another, and also copy it to OneDrive. After the copy is complete, I delete all the files from the source folder.
You will need to create a “Batch” script file for this. I will suggest you download Notepad++, which can warn you of errors, and also offer syntax support. Once installed, follow the steps below:
- Open Notepad++.
- Create a New File and save it as “Daily Backup”, and make sure to choose extension as.BAT as shown in the image below.
- Now type your commands, and in my case, it looks like this.
- Now, Right-click on the batch file and select Create Shortcut.
- Make sure to rename it to some that is meaningful full. You can either use F2 or select the file, and then again click on the Name of the file, and it will open the edit box.
- Now copy the shortcut.
- Next, we will do the same thing we did for the simple commands.
- Go to C:\Users\YOUR-USERNAME\AppData\Roaming\Microsoft\Windows\Start Menu\Programs.
- Paste the Shortcut here.
Now you can say “Hey Cortana, open My Backup“, and it will execute the commands. If you noticed, I have added a pause in the script to make sure you to get see what happened during the copy process. So in case of errors, you will know about it.
Pro Tip: First, always use simple names. Even though Cortana can understand voice commands clearly, I have seen many a time that it recognizes to fail. Second, make sure the commands don’t sound like native commands which Cortana can execute. E.g., Shutdown, Music, etc. Lastly, always create a backup of your script, and save it online.