Aliases in Windows command prompt

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Aliases in Windows command prompt

Message par ForumBot »

Aliases in Windows command prompt
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Aliases in Windows command prompt

Message par ForumBot »

To add to josh's answer,

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

-
Create a .bat or .cmd file with your `DOSKEY` commands.

-
Run regedit and go to `HKEY_CURRENT_USER\Software\Microsoft\Command Processor`

-
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 or Windows 11**, add the entry to `HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Command Processor` instead.

(For Windows 11, also note that by default the "Terminal App" points to PowerShell. Search "cmd" for command prompt.)

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

```
@echo off

:: Temporary system path at cmd startup

set PATH=%PATH%;"C:\Program Files\Sublime Text 2\"

:: Add to path by command

DOSKEY add_python26=set PATH=%PATH%;"C:\Python26\"
DOSKEY add_python33=set PATH=%PATH%;"C:\Python33\"

:: Commands

DOSKEY ls=dir /B $*
DOSKEY 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 directories

DOSKEY 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

*(Réponse tronquée)*
Répondre

Revenir à « Performance & Dépannage »