Skip navigation

JSI Tip 6140. CMD.exe runs files that DO NOT have executable file name extensions?

When you use a command prompt (CMD.EXE) or a batch file to open a file that does NOT have an executable file name extension, the file may run as a program, instead of being opened in the program that is registered for that file type? You type filename or filename.txt and the filename.txt file runs, instead of being opened by Notepad?

This behavior can occur if the file is a binary image that contains an executable header. The file may be a .com or .exe file that was been renamed with a different file name extension, and you DO NOT specify the program that CMD.exe should use to open the file.

When you use a file name as a command at a command prompt or in a line of script, Windows NT-based operating systems (Windows NT, Windows 2000, Windows XP, Windows .NET) invoke the CreateProcess function to open the file. If CreateProcess detects that the file is a binary image with an executable header, the file is run as a program.

To workaround this feature, open the file in Windows Explorer, or use the following syntax at a command prompt or in a line of script:

ProgramName filename.extension


notepad filename.txt

NOTE: Renaming an executable with a .txt extension is one way that a virus can be delivered to your computer.

NOTE: Windows Explorer and Internet Explorer perform additional checks before opening a file. If the extension is associated with a program, they use the associated program to open the file.

NOTE CMD.exe inspects the PATHEXT environment variable to determine what extensions are executable, but it also runs any binary image with an executable header.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.