27

The situation is that I have a portable application that needs to have a set environment variable. Otherwise it tries to set it's settings in the user program data dir.

To avoid running the executable in non-portable mode (to avoid allowing it to run without any parameters), I erased the file's ".exe" extension. But then I cannot run it, neither with the mouse (which I want) or through the start command.

Is there any way to run an executable file that has no ".exe" extension?

ouflak
  • 109
  • 1
  • 1
  • 6
rsk82
  • 1,442
  • 7
  • 21
  • 27
  • Your question is not really clear. If you accidentally deleted the .EXE extension, why can't you add it back? What's preventing you from doing so? – Karan Jul 16 '13 at 01:42
  • I've deleted it on purpose to not accidentally hit it so the program would run without any parameters. I want to be safe to only run the program with options at start. – rsk82 Jul 20 '13 at 22:20

3 Answers3

18

Any file with any extension and first two bytes MZ will be treated like an EXE.

Try following:

  1. Create a new a.txt file,
  2. Type in it MZ, save it.
  3. Open cmd, go to its folder,
  4. Type a.txt and see the error message.

Replace MZ with MS and try again - this time notepad will run with file opened.

  • 1
    Doesn't work in Windows 10. It always shows `'' is not recognized as an internal or external command, operable program or batch file.` error – phuclv Mar 22 '18 at 04:35
  • 1
    I've just tried at home with in Windows 10 Pro and it indeed shows an error `This version of D:\test.txt is not compatible with the version of Windows you're running. Check your computer's system information and then contact the software publisher.` previously I used Windows 10 LTSB at work and it didn't work – phuclv Apr 07 '18 at 16:46
  • It still works on my Windows 10 X64, the same example as above. – Петър Петров Nov 07 '18 at 15:12
  • 1
    If you try to execute a file without any extension, it will throw a `'file' is not recognized` error. – Stevoisiak Oct 14 '19 at 17:03
17

Yes – simply entering the program's full filename usually works. (The .exe requirement only exists in the GUI shell.)

(It might be that the file needs an extension, though – so if you can't get MyProgram to run, rename it to MyProgram.notexe or MyProgram.lol and try again.)

u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • 1
    This surprised me once, when I renamed a self-extracting Zip file from `.exe` to `.zip`, tried to open it through cmd.exe, and it *still* ran the self-extractor instead of opening WinZip. – u1686_grawity Jul 15 '13 at 10:37
  • I didn't know the trick with changing extension, that program might need some dummy one, thats not so intuitive. But anyway I encountered another bummer that is the application itself needs its main executable to have a strict name. – rsk82 Jul 15 '13 at 10:44
  • 1
    Anything that starts with `MZ` will be executed by cmd, check below – Петър Петров Sep 16 '16 at 13:56
5

I tried to run process from file without the .exe extension. When I failed to do so from cmd.exe I give a try some powershell commands. Here is one:

Start-Process

The documentation says about Default syntax and UseShellExecute. With just:

Start-Process -FilePath .\my-program -Wait -NoNewWindow

the command uses UseShellExecute syntax and returns error about not associated application to that file type. To force the Default syntax I added parameter that the UseShellExecute doesn't have:

Start-Process -FilePath .\my-program -Wait -RedirectStandardError ./error.txt -NoNewWindow

My program was started and wrote output to the console. This was enough for me, because I needed it only for test purpose.

Sarrus
  • 151
  • 1
  • 2