public static ShellFileType GetExeType(string file) { const uint shgfiExetype = 0x000002000; var type = ShellFileType.FileNotFound; if (!File.Exists(file)) { return(type); } ShFileinfo shinfo = new ShFileinfo(); IntPtr ptr = Shell32.SHGetFileInfo(file, 128, ref shinfo, (uint)Marshal.SizeOf(shinfo), shgfiExetype); int wparam = ptr.ToInt32(); int loWord = wparam & 0xffff; int hiWord = wparam >> 16; type = ShellFileType.Unknown; if (wparam != 0) { if (hiWord == 0x0000 && loWord == 0x5a4d) { type = ShellFileType.Dos; } else if (hiWord == 0x0000 && loWord == 0x4550) { type = ShellFileType.Console; } else if (hiWord != 0x0000 && (loWord == 0x454E || loWord == 0x4550 || loWord == 0x454C)) { type = ShellFileType.Windows; } } return(type); }
internal static extern IntPtr SHGetFileInfo( string pszPath, uint dwFileAttributes, ref ShFileinfo psfi, uint cbSizeFileInfo, uint uFlags);
public static extern IntPtr SHGetFileInfo(string pszPath, uint dwFileAttributes, ref ShFileinfo psfi, uint cbSizeFileInfo, uint uFlags);