In a C# application, I\'d like to determine whether another .NET application is a Console application or not.
Can this be done using the reflection APIs?
EDI
The SHGetFileInfo function can do this:
[DllImport("shell32.dll", CharSet=CharSet.Auto, EntryPoint="SHGetFileInfo")]
public static extern ExeType GetExeType(string pszPath, uint dwFileAttributes = 0, IntPtr psfi = default(IntPtr), uint cbFileInfo = 0, uint uFlags = 0x2000);
[Flags]
public enum ExeType
{
None = 0,
WinNT = 0x04000000,
PE = ((int)'P') | ((int)'E' << 8),
NE = ((int)'N') | ((int)'E' << 8),
MZ = ((int)'M') | ((int)'Z' << 8),
}
Then, according to the specification, if it's only MZ or PE, it is opened in console, otherwise (if a version is specified), it is open in a window.
ExeType type = GetExeType("program.exe");
if(type == ExeType.PE || type == ExeType.MZ) return "console";
else return "window";