What is the difference between .BAT and .EXE files?
BAT and EXE files may seem the same on the surface. For example, both files are are commonly found in a program's root installation directory and both run programs when opened. Often, they even have the same Windows icon. To the average user, .BAT and .EXE files appear nearly identical. However, a closer look at BAT and EXE files reveals that they are actually quite different, even though they may often serve the same end-user purpose.
BAT files are simple text scripts, and can be created and modified in text editor programs such as Microsoft Notepad or WordPad. The language used by BAT files is not too difficult to learn, especially for simple scripting purposes. An easy way to create a BAT file is to first create a .TXT file, save it, and then change its extension to ".bat." You can reopen the new BAT file directly in text editor program to change the code.
NOTE: Be careful not to double-click a BAT file assuming that it will open in a text editor, because Windows may execute the code instead.
When a BAT file is run, the code is executed by a Windows built-in utility called the Windows Command-Line Interpreter (CLI). This is a "shell" program that allows users to type and execute DOS-like commands. When the Windows CLI executes a BAT file, each command is executed sequentially until all commands are completed. Interestingly, BAT files are actually run by an EXE program with the name cmd.exe.
Below is a screenshot of the cmd.exe program:
The following code is from a simple batch file that creates a text file with the string "FileInfo.com - The File Extensions Resource" and then opens the file with Microsoft Notepad:
REM - example.bat
ECHO FileInfo.com - The File Extensions Resource > output.txt
START NOTEPAD.EXE output.txt
EXE files are different from BAT files since they contain executable binary data rather than plain text commands. They are stored in the Portable Executable (PE) format, which Windows uses in both 32-bit and 64-bit operating systems to store executable files. The EXE file format includes various headers and sections that tell Windows how to run a program. Some portions of an EXE file may contain program code while others may contain resource data. When an EXE file is opened, Windows places the executable code in memory, then runs the program.
Unlike BAT files, EXE files are rarely built manually because of their complexity. Several developer IDEs, such as Microsoft Visual Studio, allow developers to create executable files for their programs. These development programs compile program code into an EXE file and bundle the necessary resource files with the application. Other programs, such as Corel WinZip, Microsoft IExpress, and Flexera InstallShield can be used to create self-extracting archives or installation executable files. These programs guide users through a process of bundling files and resources into a single EXE file or an EXE file with other installation file resources.
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.