doskey com=a long command $*
Here $* expands to everything typed after com. For example, com Hi! would be expanded to a long command Hi!
- This not limited to the
cmd.exe shell – it works with any program that uses a Win32 console window. (For example, for Python's interactive shell, use doskey /exefile:python.exe ...)
See doskey /? for usage. The aliases can also be added programatically; see Console Aliases for the API.
To apply aliases automatically whenever cmd.exe is launched:
Put them in a text file, in the form alias=expansion:
com=very long example command
cd=cd /d $*
I keep my aliases in %AppData%\doskey.txt.
Create a batch script containing the doskey command:
@echo off
doskey /macrofile:"%AppData%\doskey.txt"
Of course, point /macrofile to the location you have chosen in step 1.
A good name for this script is %AppData%\autorun.cmd.
In Registry, open key HKEY_CURRENT_USER\Software\Microsoft\Command Processor and point the value AutoRun to the script.
- Run
regedit, navigate to the given key.
- If a value named
AutoRun does not exist, create it: right-click → New → String
- Modify the associated data to point to wherever your autorun script from #2 is located.