Getting Executable Type


Click here to change the theme.

The following program is a sample use of GetBinaryType for determining the type of executable a file is. Evidently GetBinaryType does not differentiate between console and GUI programs but otherwise it does provide useful information.

#define STRICT 1
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>

int main(int argc, char *argv[], char *envp[]) {
	DWORD BinaryType;
if (argc <= 1) {
	fputs("Empty command line; nothing to do.\n", stderr);
	return 32;
	}
puts(argv[1]);
if (!GetBinaryType(argv[1], &BinaryType)) {
	puts("\tIs not executable");
	return 4;
	}
switch (BinaryType) {
	case SCS_32BIT_BINARY:
		puts("\tIs a Win32-based application");
		break;
	case SCS_DOS_BINARY:
		puts("\tIs a MS-DOS - based application");
		break;
	case SCS_OS216_BINARY:
		puts("\tIs a 16-bit OS/2-based application");
		break;
	case SCS_PIF_BINARY:
		puts("\tIs a PIF file that executes an MS-DOS - based application");
		break;
	case SCS_POSIX_BINARY:
		puts("\tIs a POSIX - based application");
		break;
	case SCS_WOW_BINARY:
		puts("\tIs a 16-bit Windows-based application");
		break;
	default:
		puts("\tIs an unknown subsystem application");
	}
return 0;
}