Create macros with the DOSKEY utility in Windows NT

The DOSKEY utility allows you to create simple but powerful macros. Learn more about this powerful utility.
The command line is one of the most neglected parts of Windows NT, and many users aren't aware of everything it can do. For example, how many of your users can create a macro?

Windows NT includes a powerful DOSKEY utility that allows you to create simple but powerful macros. It even features the ALIASES command. When you enter a command, the shell checks if there's a DOSKEY macro present in memory before checking for internal commands.

Here's the basic syntax for DOSKEY macros. To access all other options, enter DOSKEY /? at the command prompt.

DOSKEY [macroname=[command]]

Let's look at some sample macros.

DOSKEY c=cls

This macro allows you to enter c at the command prompt instead of cls to clear the screen.

DOSKEY d=dir /o /p $*

This macro displays the contents of the folder, listed alphabetically one screen at a time.

You can also run more than one command with a macro. Here's an example:

DOSKEY nd=md $1$Tcd $1

Entering nd myfolder creates a new folder (myfolder) and switches to it. This is basically the same as entering the md myfolder and cd myfolder commands separately.

Once you create your collection of macros, save them to a file. To do so, enter DOSKEY /macros > filename.

You can load them into memory by entering DOSKEY /macrofile=filename. This is especially useful because macros don't persist through the session, meaning they're lost once you close the command prompt. By storing them in a file, you can easily reload them later. If you want to delete a macro from memory, enter DOSKEY macroname =.

However, macros do have limitations. For example, you can't run them from a batch file. In addition, their powerful nature can render the command prompt completely inoperable. For instance, you could create macros that have the same names as commands, such as DIR, COPY, and even DOSKEY itself.


Editor's Picks