Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

While at work, I want to use the CLI to be more productive on my Windows machine. What command, in Windows, would be a replacement for the alias command?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted
doskey com=a long command $*

Here $* expands to everything typed after com. For example, com Hi! would be expanded to a long command Hi!

  • This not limited to the cmd.exe shell – it works with any program that uses a Win32 console window. (For example, for Python's interactive shell, use doskey /exefile:python.exe ...)

See doskey /? for usage. The aliases can also be added programatically; see Console Aliases for the API.


To apply aliases automatically whenever cmd.exe is launched:

  1. Put them in a text file, in the form alias=expansion:

    com=very long example command
    cd=cd /d $*
    

    I keep my aliases in %AppData%\doskey.txt.

  2. Create a batch script containing the doskey command:

    @echo off
    
    doskey /macrofile:"%AppData%\doskey.txt"
    

    Of course, point /macrofile to the location you have chosen in step 1.

    A good name for this script is %AppData%\autorun.cmd.

  3. In Registry, open key HKEY_CURRENT_USER\Software\Microsoft\Command Processor and point the value AutoRun to the script.

    1. Run regedit, navigate to the given key.
    2. If a value named AutoRun does not exist, create it: right-click → New → String
    3. Modify the associated data to point to wherever your autorun script from #2 is located.
share|improve this answer
    
+1: doskey is old school. –  surfasb Dec 28 '11 at 1:45
    
I attempted this method on windows 7, but had no luck. when I attempt to directly execute the autorun.cmd, I get an Invalid macro definition error (I turned @echo on to see the output). are there any suggestions for what might cause this? –  ewok May 15 '12 at 15:22
1  
nevermind. Just to let you know, there is an error in your answer. the autorun.cmd file needs to say doskey /macrofile=.... note the = instead of the : –  ewok May 15 '12 at 15:26
add comment

I assume you mean the "alias" command. Dos/NT command prompts support "alias" as a command with the following syntax:

alias

See the wikipedia article for details: http://en.wikipedia.org/wiki/Alias_(command)

share|improve this answer
    
Doesn't look like it, I just tried it. Win XP. But that wikipedia article does mention powershell and 4DOS and 4NT having a command for aliases but maybe not that syntax. –  barlop Apr 11 '11 at 20:05
    
What about using Set? I just tested in XP, set ckh = "George" and it set an environment variable ckd as "George". Is this an analog to alias? –  music2myear Apr 11 '11 at 20:25
    
@music2myyear No. An alias is like a substitution. So typing C:\>doskey tt=blah <ENTER> that sets up an alias tt=blah, means when you type tt and press ENTER, then it acts like you typed blah and pressed enter. So it's like a shortcut. With set, if you do set ckh=George Then ckh ENTER will still be ckh ENTER. But %ckh% will use the contents of the ckh environemnt variable i.e. George. The %s are not so convenient as with an alias, –  barlop Apr 11 '11 at 23:31
    
@music2myyear but it's a very different concept really. A variable is like a container with a name and a value and is meant to change at times you want. An alias is like a shorthand way of saying something, it's more static.. if you kept changing your aliases you'd get confused.. 'cos they're meant to be easily memorable shorthands for specific commands with certain options you don't want to have to retype. –  barlop Apr 11 '11 at 23:33
    
Got it and thank you for the explanation. I've never much gotten into programming or scripting or admin-ing on *nix systems and so was (obviously) not familiar with the concept. But now I'm a little more so thanks to y'all. –  music2myear Apr 12 '11 at 2:45
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.