The .COM file extension

November 1, 2010 at 05:06:01
Specs: Windows XP and later, N/A
I thought I knew what the .COM file format was all about, but now I've just realised something that surprised me.

I always thought the .COM files were MS-DOS executables and therefore, by implication, 16-bit. But I've just come across 32-bit .COM executables. For example C:\WINDOWS\system32\chcp.com is a 32-bit executable on Windows XP and later.

Is it just me, or did many other people know that .COM files could be 32-bit as well?

How does one create such a file? (The last time I created a .COM file was using the Tiny memory model in a 16-bit version of Visual Studio)


See More: The .COM file extension

Report •

#1
November 1, 2010 at 05:28:09
Edit: "no ill effect" is a little strong I should have said that it can still be run... It does seem to stop xp from displaying the icon of the executable.


I believe that the nature of certain dos executables means that windows actually tests what type an executable is. It's even possible to rename .exe as .com with no ill effect:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Judago>for %a in (cmd.exe) do copy "%~f$path:a" test.co

C:\Documents and Settings\Judago>copy "C:\WINDOWS\system32\cmd.exe" test.com
        1 file(s) copied.

C:\Documents and Settings\Judago>test
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\Judago>test.com /c echo .com?&ver
.com?

Microsoft Windows XP [Version 5.1.2600]

C:\Documents and Settings\Judago>


Report •

#2
November 1, 2010 at 05:35:12
chcp.com is a 16 bit MSDOS executable that can be used only in the DOS subsystem.
In Windows the "com" extension is simply an alias for "exe" and works the same way. You can change the extension of an application to "com" (or "scr") and it will still work but existing shortcuts of course will not.

Report •

#3
November 1, 2010 at 06:37:33
LOL

LIST 1 37% 07/04/2003 12:00 chcp.com
MZÉ ♥ ♦    ╕ @ ╚ ♫▼║♫ ┤ ═!╕☺L═!T
his program cannot be run in DOS mode.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
November 1, 2010 at 07:22:23
I see, so they're really just .EXEs renamed to .COM (whereas a true .COM is a bit-by-bit image of a DOS executable as it would be when loaded into memory, i.e. no headers etc.) I wonder why they do that. Why not just leave these files as .EXE? (i.e. chcp.exe)

Report •

#5
November 1, 2010 at 07:56:41
These programs came from DOS where they had a COM extension. Changing this could cause compatibility issues with scripts and other applications. If it isn't broken, don't fix it.

Report •

#6
November 1, 2010 at 08:48:08
What I thought I knew back in the DOS 3x to 6x days was .com or .bin is an image loaded into the current segment. Accordingly, it could be no bigger 64K.


=====================================
Life is too important to be taken seriously.

M2


Report •

#7
November 1, 2010 at 09:07:45
In the 16 bit DOS world there was a very real difference between the COM and EXE formats. In the COM format all of the programs code, data, and stack had to fit in one 64K segment. This was simple but suitable only for small programs. With the EXE format the programmer was able to specify segments for specific purposes.

32 bit Windows doesn't use segments so the distinction is meaningless and the COM extension is maintained only for compatibility. When you try to run a file with either extension Windows will check the file header to properly identify the format and run it accordingly. A true 32 bit COM format was never developed. All code and data fits within the process's private 2GB address space without segments. I think few programmers miss them.


Report •

Ask Question