Aliases in Windows command prompt Aliases in Windows command prompt windows windows

Aliases in Windows command prompt


To add to josh's answer,

you may make the alias(es) persistent with the following steps,

  1. Create a .bat or .cmd file with your DOSKEY commands.
  2. Run regedit and go to HKEY_CURRENT_USER\Software\Microsoft\Command Processor
  3. Add String Value entry with the name AutoRun and the full path of your .bat/.cmd file.

    For example, %USERPROFILE%\alias.cmd, replacing the initial segment of the path with %USERPROFILE% is useful for syncing among multiple machines.

This way, every time cmd is run, the aliases are loaded.

For Windows 10, add the entry to HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor instead.

For completeness, here is a template to illustrate the kind of aliases one may find useful.

@echo off:: Temporary system path at cmd startupset PATH=%PATH%;"C:\Program Files\Sublime Text 2\":: Add to path by commandDOSKEY add_python26=set PATH=%PATH%;"C:\Python26\"DOSKEY add_python33=set PATH=%PATH%;"C:\Python33\":: CommandsDOSKEY ls=dir /BDOSKEY sublime=sublime_text $*      ::sublime_text.exe is name of the executable. By adding a temporary entry to system path, we don't have to write the whole directory anymore.DOSKEY gsp="C:\Program Files (x86)\Sketchpad5\GSP505en.exe"DOSKEY alias=notepad %USERPROFILE%\Dropbox\alias.cmd:: Common directoriesDOSKEY dropbox=cd "%USERPROFILE%\Dropbox\$*"DOSKEY research=cd %USERPROFILE%\Dropbox\Research\

  • Note that the $* syntax works after a directory string as well as an executable which takes in arguments. So in the above example, the user-defined command dropbox research points to the same directory as research.
  • As Rivenfall pointed out, it is a good idea to include a command that allows for convenient editing of the alias.cmd file. See alias above. If you are in a cmd session, enter cmd to restart cmd and reload the alias.cmd file.

When I searched the internet for an answer to the question, somehow the discussions were either focused on persistence only or on some usage of DOSKEY only. I hope someone will benefit from these two aspects being together here!


Here's a .reg file to help you install the alias.cmd. It's set now as an example to a dropbox folder as suggested above.

Windows Registry Editor Version 5.00[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]"AutoRun"="%USERPROFILE%\\alias.cmd"

For single-user applications, the above will do. Nevertheless, there are situations where it is necessary to check whether alias.cmd exists first in the registry key. See example below.

In a C:\Users\Public\init.cmd file hosting potentially cross-user configurations:

@ECHO OFFREM Add other configurations as neededIF EXIST "%USERPROFILE%\alias.cmd" ( CALL "%USERPROFILE%\alias.cmd" )

The registry key should be updated correspondly to C:\Users\Public\init.cmd or, using the .reg file:

Windows Registry Editor Version 5.00[HKEY_CURRENT_USER\Software\Microsoft\Command Processor]"AutoRun"="C:\\Users\\Public\\init.cmd"


You need to pass the parameters, try this:

doskey np=notepad++.exe $*

Edit (responding to Romonov's comment) Q: Is there any way I can make the command prompt remember so I don't have to run this each time I open a new command prompt?

doskey is a textual command that is interpreted by the command processor (e.g. cmd.exe), it can't know to modify state in some other process (especially one that hasn't started yet).

People that use doskey to setup their initial command shell environments typically use the /K option (often via a shortcut) to run a batch file which does all the common setup (like- set window's title, colors, etc).

cmd.exe /K env.cmd

env.cmd:

title "Foo Bar"doskey np=notepad++.exe $*...


If you're just going for some simple commands, you could follow these steps:

  1. Create a folder called C:\Aliases
  2. Add C:\Aliases to your path (so any files in it will be found every time)
  3. Create a .bat file in C:\Aliases for each of the aliases you want

Maybe overkill, but unlike the (otherwise excellent) answer from @Argyll, this solves the problem of this loading every time.

For instance, I have a file called dig2.bat with the following in it:

@echo offecho.dig +noall +answer %1

Your np file would just have the following:

@echo offecho.notepad++.exe %1

Then just add the C:\Aliases folder to your PATH environment variable. If you have CMD or PowerShell already opened you will need to restart it.

FWIW, I have about 20 aliases (separate .bat files) in my C:\Aliases directory - I just create new ones as necessary. Maybe not the neatest, but it works fine.

UPDATE: Per an excellent suggestion from user @Mav, it's even better to use %* rather than %1, so you can pass multiple files to the command, e.g.:

@echo offecho.notepad++.exe %*

That way, you could do this:

np c:\temp\abc.txt c:\temp\def.txt c:\temp\ghi.txt

and it will open all 3 files.