Create permanent DOSKEY in Windows cmd
Create a macro definition file, for instance in notepad
; name it at will and save it anywhere (for instance, in next example I used filename macros.doskey
in d:\bat\
folder).
Alternatively, doskey /macros>d:\bat\macros.doskey
command will list all current macro definitions into d:\bat\macros.doskey
file.
A sample macro definition file could be as follows (note that ==>
is my command prompt specified by prompt $Q$Q$G$S
command):
==> type d:\bat\macros.doskey
ls=dir /B $1
ip=ipconfig $*
Then, next commands should do the job:
==> reg add "HKCU\Software\Microsoft\Command Processor" /v Autorun /d "doskey /macrofile=\"d:\bat\macros.doskey\"" /f
The operation completed successfully.
==> reg query "HKCU\Software\Microsoft\Command Processor" /v Autorun
HKEY_CURRENT_USER\Software\Microsoft\Command Processor
Autorun REG_SZ doskey /macrofile="d:\bat\macros.doskey"
For explanation, read cmd /?
:
If
/D
was NOT specified on the command line, then whenCMD.EXE
starts, it looks for the followingREG_SZ
/REG_EXPAND_SZ
registry variables, and if either or both are present, they are executed first.HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun
and/or
HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun
Disclaimer: some AutoRun
settings could eventuate in unlooked-for unwanted behaviour, e.g. as decribed in Hidden gotcha: The command processor’s AutoRun setting
Read Save and restore macro definitions; you could prepare a valid macros.cmd
script file in one step:
==> >macros.cmd (@for /F "delims=" %G in ('doskey /macros') do @echo DOSKEY %G)
==> type macros.cmd
DOSKEY ip=ipconfig $*
DOSKEY ls=dir /B $1
==>
Please keep in mind that you cannot run a Doskey macro from a batch file.
Create a file to store your macros (DOSKEYs).
"C:\bat\macros.doskey"†ls=dir $* $T up=cd.. $T ex=exit $T np=notepad
Go to the registry editor.
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\
Right-click and add a new "String Value" sub-key. Name it Autorun.
Right-click -> New -> String Value- Right-click it and Modify the Value data.
Right-click -> Modify -> Value data ->DOSKEY /MACROFILE="C:\bat\macros.doskey"
- Good to go.
† Note that the file does not have to be saved as a .doskey file.
† Also note that the token $T
is required if you're making multiple DOSKEYs.
I do it this way without registry updates. Pin "Command Prompt" to the task bar, then right click the icon on the task bar; from the popup select "Properties". In the "Target:" field enter the following:
%windir%\system32\cmd.exe /F:on /k doskey /macrofile=C:\cmds\macros.txt && Title CONSOLE
Then create the C:\cmds\
folder, open a command prompt and set up your desired "doskey" macros:
doskey ip=ipconfig
doskey ls=dir /w
Last, create the macro file:
doskey /macros > C:\cmds\macros.txt
This will change the "Command Prompt" icon in the task bar to invoke doskey
using the macrofile on startup. You can use the "Command Prompt" in the START menu if you don't need the macros.