What is the difference between the a.bat, a.com and a.exe extensions?
Originally, a .COM
file was a literal blob of 8086 code (that is, 16-bit x86). It is meant to be loaded at a fixed address, and the loader would jump straight to the first byte of its address. It's also limited in size.
An .EXE
file has more header information. So it has required structures for things like dynamic linking, where code from a DLL can be patched into the .EXE
's memory space at load time.. It originally comes from DOS, but it's today used in Windows.
However DOS and Windows eventually went to a model where the file extension in a .COM
and .EXE
didn't mean anything. The program loader first checks the first two bytes of the file. If it happens to be the string MZ
(legend has it this stands for the initials of an early Microsoft employee), it will treat it as an EXE
, otherwise it will load it as if it were a COM
file. Since MZ
doesn't map to a sensible x86 instruction to start a program, they can get away with this. Net effect: In some versions of DOS/Windows, an .EXE
can be named with .COM
and vice versa. For example, in many versions of DOS/Windows, the famous COMMAND.COM
was actually an EXE
.
I am not sure how much the previous paragraph applies to NT based versions of Windows. I'd imagine by now they've abandoned the .COM
stuff altogether.
Lastly, a .BAT
file is a list of commands to be executed as if you typed them at your command prompt. However these days most people name them as .CMD
.