What is the difference between the a.bat, a.com and a.exe extensions?
9 Answers
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
.
-
17**MZ** stands for **MORIN Zobowski** - He designed and implemented the first versions of EXE headers. :) – this. __curious_geek Jan 22 '10 at 07:44
-
1You can rename any .exe file to .com and it will run fine - it makes no difference. – Nathan Osman Jan 22 '10 at 07:48
-
Just because it runs it doesn't mean it works! EXE and COM are like 2 completely different model of cars from the same manufacture. – this. __curious_geek Jan 22 '10 at 07:50
-
@George Edison - What I meant was, if you assemble "mov ax, 4c00h ; int 21h", then name that with .COM, will it do anything if you run it? Does this still work on Win7? – asveikau Jan 22 '10 at 07:52
-
I use Vista :) What I meant was that Windows will load the executable based on headers/content, not extension. It is ignored - at least when it comes to exe/com. As for real .com apps, NT based OS's will not run 16 bit executable files. – Nathan Osman Jan 22 '10 at 08:49
-
1@George Edison I'm pretty sure 32-bit NT will still run Win16 EXEs. – asveikau Jan 22 '10 at 17:51
-
I believe that a "call 0" would terminate the program, as it's a holdover from CP/M days. The zero refers to the first 16 bit word of the PSP, which is an int 20h (no exit code used, but causes a program to terminate) – Arthur Kalliokoski Mar 08 '10 at 02:21
-
16 bit COM files can run in NTVDM on all 32 bit Microsoft OS. 16 bit was deprecated in 64 bit OS. – Prof. Falken Jul 27 '11 at 14:26
-
The question is pretty vague, but a more complete answer could include which of the 3 is executed if they are in the same directory ([presumably .com, depending on environment variable PATHEXT](http://stackoverflow.com/questions/605101/order-in-which-command-prompt-executes-files-with-the-same-name-a-bat-vs-a-cmd/605139#605139)). – Peter Mortensen Jun 06 '14 at 18:32
-
4In Visual Studio, "devenv.exe" is the GUI version of Visual Studio and "devenv.com" is the command line build tool version. It's really an EXE, just renamed as .com. But because ".com" has precedence in the PATH search, typing "devenv" in a console window launches the command line build tool. Neat trick should ever want to have a Windows GUI EXE also have a command line version of itself. – selbie Jun 06 '14 at 20:02
-
@KJ MZ stands for "Mark Zbikowski". The guy who designed the format for the EXE executable file and its header for DOS. https://en.wikipedia.org/wiki/Mark_Zbikowski – this. __curious_geek Jun 06 '21 at 12:29
.bat is a batch file. It is interpreted.
.exe is a regular executable program file.
A .com file, at least for MS-DOS, has many meta-data missing and is loaded into a specific offset in the main memory. It is smaller than .exe

- 19,057
- 21
- 82
- 129
I assume you mean for Windows?
"a.bat" is supposed to be a batch file, the Windows/DOS equivalent of a script file.
"a.com" and "a.exe" are supposed to be equivalent these days. However, back in the Windows 3.x days, a "com" file was a DOS executable, where an "exe" file was a portable executable, or a Windows-based executable. This is a gotcha these days, as files in the format "www.example.com" can exist on your hard drive, and many people mistake such a file for a web link. Even worse, Windows typically tries executing "com" files before "exe" files.

- 30,738
- 21
- 105
- 131

- 67
- 2
-
Order of Precedence in Locating Executable Files (http://support.microsoft.com/kb/35284) is also useful sometimes when you're in a bind (rarely though). – Liao Jan 22 '10 at 07:22
-
3
-
2Actually, Portable Executables existed before Windows. See Wikipedia. – Nathan Osman Jan 22 '10 at 07:49
While EXE and BAT files often serve a similar purpose, they use completely different file formats. Both file types can be used for creating executable content in Windows, but BAT files are limited in the commands they can perform. Since BAT files contain human-readable text, they can be easily edited and therefore are often used for custom scripting tasks. EXE files, on the other hand, contain complex binary data that is built using a compiler. Since EXE files support more complex commands than BAT files, most Windows applications are saved in the EXE format.
I was also looking for the same query and found something that have pasted here.
Please refer the below link, you will find it useful, it perfectly answers your question:
Difference between .BAT and .EXE

- 269
- 2
- 4
- 14
A bat(ch) file is a script that is executed by the command interpretor.
A exe file is compiled binary code to be executed directly on the cpu.
A com file is a relic from the past to create a small exe.

- 52,876
- 38
- 145
- 202
.BAT - Batch File: list of commands (basically a text file with command-line commands)
.COM - DOS Executable loaded into a fixed block of memory (stems back from before multi-tasking)
.EXE - Executable file - standard application on the Windows platform

- 15,244
- 5
- 33
- 45
Actually, .com and .exe are both binary executable files, whereas .bat is basically a batch file. Now suppose you have got many files with the same name, but different extensions.
For instance, a.com
, a.exe
and if you are running through the command prompt file a. It will first execute a.com
(only if it exists), else it will run a.exe
. Or say a.exe
is also not there then it will look for a.bat
execution.

- 30,738
- 21
- 105
- 131

- 151
- 5
-
See also *[Order in which the command prompt executes files with the same name (a.bat vs a.cmd vs a.exe)](http://stackoverflow.com/questions/605101/order-in-which-command-prompt-executes-files-with-the-same-name-a-bat-vs-a-cmd/605139#605139)* – Peter Mortensen Jun 06 '14 at 18:40
- A .BAT (short for "batch") file is a plain text file that contains a series of Windows commands.
- An .EXE (short for "executable") file is a binary file that contains much more complex executable binary code.
- A .COM file was a DOS executable and nowadays its same as .EXE.

- 1,145
- 11
- 6
.bat file effects directly on the performance of CPU. While, the .exe file will be compiled by interpreter and then executed on CPU.

- 50
- 1
- 2
- 10