Subsystem software check
I have an .exe created with Windows Subsystem. I will copy this .exe to another .exe and I run:
editbin.exe /SUBSYSTEM:CONSOLE my.exe
So, I intend to have an .exe that works with a GUI and another .exe that is designed for command line operations (no GUI).
How can I check which subsystem is currently active in my C ++ code?
source to share
The type of subsystem (GUI, console, etc.) is stored in the PE header, which you can access through ImageHlp functions. You can get it with the following code:
// Retrieve the header for the exe. GetModuleHandle(NULL) returns base address
// of exe.
PIMAGE_NT_HEADERS header = ImageNtHeader((PVOID)GetModuleHandle(NULL));
if (header->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_CUI)
{
// Console application.
}
Relevant MSDN entries:
source to share
Take a look at the ImageLoad function in the Imagehlp library. This returns a LOADED_IMAGE structure that has an IMAGE_NT_HEADERS structure in the FileHeader field. The OptionalHeader field in this structure is IMAGE_OPTIONAL_HEADER , which has a Subsytem that contains the information you want.
source to share