Can EXE always be replaced with COM?

Preview

Our antivirus software didn't allow me to copy an EXE file into my Windows 7 startup folder (calc.exe for example) since it's an EXE file

So I renamed it to a COM file and then copied it and it allowed it (very professional).

And of course - calc.com does work.

Which led me to ask (only for curiosity):

Question

When will an EXE program not run when renamed to COM ? Almost every exe file that I've checked worked.

I'd love to know the internals for why and why not.


It has to do with the internal format of the file. Originally .com files were simple memory images and .exe files had lots of headers associated with them. As a result you couldn't rename them. As time went on and they had to make things backward compatible, Microsoft changed it so that the OS looks at the file itself to determine what type of file it is instead of the extension. As a result when you run the renamed file Windows ignores the extension entirely. See the links below for a more extensive explanation.

Similar question

Microsoft blog explanation