Run Automatic Commands at Command Prompt

Automatic Commands If you work with a pc lengthy enough, you’ll grow to be growing a few workflows. These can be easy or complicated, however it’s in all likelihood you’ll come to be with some which can be unique to you. The greater you do along with your laptop, the much more likely you’ll grow to be the usage of the Command Prompt or the greater effective PowerShell.

Sometimes you would possibly find your self running the identical few commands each time you release PowerShell or the command activate. Instead, why not keep some time and run them routinely on launch?

What Can You Do with Automatic Commands?

Automatic Commands You might also have a workflow that sees you developing a bunch of files in a directory whenever you use Command Prompt or PowerShell. With automatic commands you could smooth that directory whenever you open a spark off. You can also use this to alternate the default directory the Command Prompt or PowerShell opens in.

Those are just a few examples. Your personal workflows will dictate what you mechanically run.

Setting Up Automatic PowerShell Commands

To run instructions mechanically in PowerShell, edit your profile. To get started, take a look at to see if you have a profile already. Open PowerShell and sort the following:

Test-Path $Profile

This will return either True or False. If it’s false, run the following command:

New-Item –Path $Profile –Type File –Force

This will overwrite any existing profile. If the preceding command again True, you probable don’t need to run this. If you need to begin over, pass proper in advance.

notepad $Profile

Put any commands you may run in PowerShell here, and they’ll routinely run each time you open it. If you’re familiar with Linux, this is basically the same as modifying your “~/.Bash_profile” document.

In most cases PowerShell’s execution coverage will save you this script from walking. This is to assist keep your machine secure. To allow your the script to run, launch PowerShell as administrator and run the subsequent:

Set-ExecutionPolicy RemoteSigned

Setting Up Automatic Command Prompt Commands

Compared to the Unix-style technique you use to automatically run instructions in PowerShell, the Command Prompt is lots more Windows-like. There are unique ways to do that, relying on the way you choose to paintings.

Method 1: The Windows Registry

Like the PowerShell technique above, this specifies a script to run whenever which you release the Command Prompt. Unlike that method, it uses the Windows Registry to define which file runs. For this example we’re assuming you need to use a report called “vehicle.Cmd.”

To create the right registry price, open the Command Prompt and run the following

reg add "HKCU\Software\Microsoft\Command Processor" /v AutoRun ^ /t REG_EXPAND_SZ /d "%"USERPROFILE"%\init.cmd" /f

Now create a file on your profile folder (commonly “C:UsersUSERNAME”) named “vehicle.Cmd.”

Edit this record with the commands you need to run routinely whilst the Command Prompt is released.

If you make a decision you no longer want this to run robotically, delete the registry key. Just run the subsequent:

reg delete "HKCU\Software\Microsoft\Command Processor" /v AutoRun

Method 2: Use a Shortcut

If you’ve got a simple case and don’t need to use the registry, you can use a desktop shortcut. As an example, in Windows 10 you could find Command Prompt inside the Start menu, right click on and pick out “Open File Location”. Copy the Command Prompt shortcut right here and paste it on your laptop.

Right-click on for your newly pasted shortcut and pick out Properties. You’ll see a section with the app’s path. It will study just like the following:

C:\Users\<Your username>\Desktop\cmd.exe

Simply alter this by adding -cmd /K and then the command or commands of your choosing. Here’s an example:

C:\Users\<Your username>\Desktop\cmd.exe -cmd /K cls

This will simply open the Command Prompt and then clear the screen. You can also chain commands by using && between them. Here’s another example:

C:\Users\<Your username>\Desktop\cmd.exe -cmd /K cls && dir

This will clear the screen and then display the contents of the director

Conclusion

Depending on what you want to do, one or greater of the above strategies have to work for you. If you end up the usage of the Command Prompt even more, test our guide to customizing how it seems.