53

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.

  • 42
    Don't copy files to the Startup folder - create shortcuts instead. – gronostaj Aug 11 '16 at 13:52
  • 4
    Yeah , this is possible , But as I said , the internals interested ,me. Not the stupid AV. :-) – Royi Namir Aug 11 '16 at 17:13
  • 11
    You can also rename it to .scr (screensaver) and it will work. – pjc50 Aug 11 '16 at 20:14
  • 2
    It's not a stupid AV (apart from not understadning that a file with a com extension can still be interpreted as a PE file). You shouldn't put executables in places that are easily written to - ideally, you only want the administrator (with an administrator token) to be allowed to write in the same directory where you have executables. Use shortcuts :) – Luaan Aug 12 '16 at 8:27
  • 1
    @Luaan I don't see how excluding EXEs and allowing shortcuts in Startup is somehow more secure than allowing both EXEs and shortcuts. Seems comparable to me. – jrw32982 Aug 17 '16 at 18:01
10

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

  • 1
    Gee. Who else thought of that? ... UNIX/Linux. – Joe Aug 16 '16 at 4:41
  • 1
    @Joe Any system that has grown organically, yeah. COM files existed long before portable executables, and were perfectly fine for quite a long time. – Luaan Aug 17 '16 at 18:05
  • @Luaan Of course you're right. I was creating/using com files on CP/M (where 64k of ram was never an issue for me). It's just interesting when one OS copies something from another one that got it right to start with - especially when they disparaged it so thoroughly for so long. – Joe Aug 19 '16 at 6:06
  • @Joe Being a Linux fan myself, I like the way it uses properties instead of extensions. – Math Man Sep 1 '16 at 14:59
  • Random factoid, but actual .COM files (MS-DOS and original CP/M) were limited to one segment (64kb) file size since the image was just directly copied into a segment and executed. The more you know, etc... – 0x90h Oct 26 '16 at 3:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.