Compdigitec Labs

« | Home | »

Launch non-exe extension files as executables

By admin | May 1, 2011

Windows does not come with a built-in way of launching executables that are without the exe extension. However, we have written a small tool called “anylaunch” which allows one to execute any file as if it were an executable. (Non-PE files will still give an error since they are not executables “XYZ is not a valid Win32 application”)

Download (anylaunch.exe) or compile from source below:

#include <iostream>
#include <windows.h>
#include <cstdlib>
//#define ZeroMemory(p,size) memset((p),0,(size))
using namespace std;

int main(int argc, char* argv[])
{
	if(argc-1 < 1) {
		cout << "No process specified" << endl;
		return 0;
	}
	
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	// must blank it
	memset(&si,0,sizeof(si));
	si.cb = sizeof(si);
	si.lpReserved = NULL;
	si.lpTitle = NULL;
	// required for GUI app
	si.dwFlags = STARTF_USESHOWWINDOW;
	si.wShowWindow = SW_MINIMIZE;
	
	bool res = CreateProcess(NULL,argv[1],NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
	if(res == false) {
		printf("CreateProcess failed (error code %d)\n", GetLastError());
		return 1;
	}

	CloseHandle(pi.hProcess);
	CloseHandle(pi.hThread);	
	return 0;
}

Download or compile the anylaunch executable and put it into the same directory as your script or into the system directory. You can use it in a command line, batch scripting or another program like so:
anylaunch “<process command line here>”

Simple examples (assuming anylaunch is in system path or current folder):

Although the biggest use of this tool is to launch non-exe PE files, like so:

file yes.123

yes.123: PE32 executable for MS Windows (GUI) Intel 80386 32-bit
Then we can use anylaunch to launch this PE file:

anylaunch yes.123
Non-exe process in Task Manager

Non-exe process in Task Manager

You may run into some problems while running this. If your command line arguments to your target application are not showing up, you should put your entire command line into one argument and escaping quotes (anylaunch “C:\\Program Files\\Mozilla Firefox\\firefox.exe” not anylaunch C:\Program Files\Mozilla Firefox\firefox.exe). Some other common problems:

Accessing a file that does not exist or is inaccessible (The system cannot find the file specified.):

cat somefile.rnd

cat: somefile.rnd: No such file or directory

anylaunch somefile.rnd

CreateProcess failed (error code 2)

Trying to run an invalid Windows application

file Untitled.png

Untitled.png: PNG image, 800 x 600, 8-bit/color RGB, non-interlaced

anylaunch.exe Untitled.png

CreateProcess failed (error code 11) (An attempt was made to load a program with an incorrect format.)
CreateProcess failed (error code 193) (%1 is not a valid Win32 application.)
etc… (invalid format error, or win32 errors, etc)

If you found this article helpful or interesting, please help Compdigitec spread the word. Don’t forget to subscribe to Compdigitec Labs for more useful and interesting articles!

Topics: Windows | 1 Comment »

One Response to “Launch non-exe extension files as executables”

  1. Greg Webb Says:
    March 28th, 2013 at 00:24

    Thank you for this utility. I’m using it as one component in replacing Notepad with Notepad++(http://notepad-plus-plus.org/) without making any changes to extensions or Notepad itself.

Comments