public static bool IsConsoleSubsystem(string executablePath) { if (Environment.OSVersion.Platform != PlatformID.Win32NT) { // Under UNIX all applications are effectively console. return true; } var info = new Shell32.SHFILEINFO(); var executableType = (uint)Shell32.SHGetFileInfo(executablePath, 0u, ref info, (uint)Marshal.SizeOf(info), Shell32.SHGFI_EXETYPE); return executableType == Shell32.MZ || executableType == Shell32.PE; }
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref Shell32.SHFILEINFO psfi, uint cbFileInfo, uint uFlags);