The situation is that I have a portable application that needs to have set environment variable. Other way it tries to set it's settings in 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 not only by mouse (which I want) but also through start command.
Is there any way to run such executable file that has no exe extension ?
23 Answers
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.)
Any file with any extension and first two bytes MZ will be treated like an EXE.
Try following:
- Create a new
a.txtfile, - Type in it
MZ, save it. - Open
cmd, go to its folder, - Type
a.txtand see the error message.
Replace MZ with MS and try again - this time notepad will run with file opened.
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:
The documentation says about Default syntax and UseShellExecute. With just:
Start-Process -FilePath .\my-program -Wait -NoNewWindowthe 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 -NoNewWindowMy program was started and wrote output to the console. This was enough for me, because I needed it only for test purpose.