22

What is the order in which the Windows command prompt executes files with the same name, but different extensions?

For example, I have a bunch of executable files: something.cmd, something.bat and something.exe. Which of these would be executed when I typed something into a command prompt (given they were on the path, etc.)? If that file did not exist which one would then be executed?

Is there a reference that describes this?

daaawx
  • 3,273
  • 2
  • 17
  • 16
Dominik Grabiec
  • 10,315
  • 5
  • 39
  • 45

1 Answers1

36

Okay, I did some quick experimentation based on some other searches I had going.

The gist is that the order of the commands is dependent on the order the extensions are stored in the PATHEXT environment variable. So initially I had:

PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.RB;.RBW

and for the example above the order in which it would run it was:

something.exe
something.bat
something.cmd

Changing the order which they were defined in the PATHEXT environment variable did indeed change the order in which they were executed.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Dominik Grabiec
  • 10,315
  • 5
  • 39
  • 45
  • 10
    If the `PATHEXT` variable is deleted, the order is the same as in the old MS-DOS days: COM, EXE, BAT and now CMD. – Aacini Nov 02 '11 at 23:53