Windows Terminal – Adding Launch Commands to Command Prompt

cmd.exewindowswindows-11windows-terminal

In a similar way to .bashrc on WSL2, I want to add custom commands to run when I open the Command Prompt in Windows Terminal, like winfetch for example. Is there any way to configure the Command Prompt profile so that it executes custom commands at startup?

Best Answer

This is possible by providing an autorun script for cmd.exe.
This is set via registry.

Open registry with regedit

navigate to:

Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor

A REG_SZ registry variable Autorun should exist with value set to 0. If registry variable not exits, create variable Autorun.

Set variable to your script, i.e. "%YOUR_PATH_TO_FILE%\my_startup_script.bat"

Example:

Computer\HKEY_CURRENT_USER\SOFTWARE\Microsoft\Command Processor\Autorun="%USERPROFILE%\my_startup_script.bat"

It is also possible to use HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun.

Further reading:
Hidden gotcha: The command processor's AutoRun setting

Related Question