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 :

cmd_aliases.txt

ls=dir $*
ps=tasklist $*
clear=cls

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.

cmd_autorun.cmd

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

And a last script to install our autorun in registry :

cmd_autorun_install.cmd

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 :
https://users.cs.jmu.edu/bernstdh/web/common/help/ntshell.php
http://superuser.com/questions/49170/create-an-alias-in-windows-xp/115259#115259