Create cmd aliases in Windows

While Linux has a simple command alias, this will require more work in windows.
We will firstly use the doskey command  :

doskey ls=dir $*

This command will create an alias ls that will execute the dir command.
The variable $* allow us to pass all of the arguments entered after the alias.
We can now use ls command instead of dir. Works very well, but alias won’t be saved when we quit 🙁

We will now set multiple commands in an external file :


ls=dir $*
ps=tasklist $*

And execute :

doskey /macrofile=c:\bin\cmd_aliases.txt

Good, but we still loose our aliases when we quit.
We’ll have to put this command in an autorun script called when cmd.exe launches.


@echo off
doskey /macrofile=c:\bin\cmd_aliases.txt

And a last script to install our autorun in registry :


reg add "hkcu\software\microsoft\command processor" /v Autorun /t reg_sz /d c:\bin\cmd_autorun.cmd

Execute cmd_autorun_install.cmd (double click)

That’s ok !

Sources :