MSDN.WhiteKnight - Stack Overflow answers
Ответ на "Как узнать тип стороннего приложения C#?"
Answer 765851
Можно использовать функцию SHGetFileInfo с параметром SHGFI_EXETYPE:
public const uint SHGFI_EXETYPE = 0x000002000; [DllImport("shell32.dll", CharSet = CharSet.Auto)] public static extern int SHGetFileInfo(string pszPath, uint dwFileAttributes, IntPtr psfi, uint cbFileInfo, uint uFlags); public static void PrintExeType(string file) { int res = SHGetFileInfo(file, 0, IntPtr.Zero, 0, SHGFI_EXETYPE); int lowWord = res & 0xffff; int hiWord = res >> 16; if (res != 0) { if (hiWord == 0x0000 && lowWord == 0x5a4d /*MZ*/) { MessageBox.Show("DOS application"); } else if (hiWord == 0x0000 && lowWord == 0x4550 /*PE*/) { MessageBox.Show("Console application"); } else if ((hiWord != 0x0000) && (lowWord == 0x454E/*NE*/ || lowWord == 0x4550 /*PE*/)) { MessageBox.Show("GUI application"); } else MessageBox.Show("Unknown"); } else MessageBox.Show("Not executable"); }
Content is retrieved from StackExchange API.
Auto-generated by ruso-archive tools.