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
doskey /macros>d:\bat\macros.doskey command will list all current macro definitions into
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
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
Autorun REG_SZ doskey /macrofile="d:\bat\macros.doskey"
For explanation, read
/D was NOT specified on the command line, then when
starts, it looks for the following
variables, and if either or both are present, they are executed first.
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.