//In ASCII representation, 0x5A4D is MZ, the initials of Mark Zbikowski, one of the original architects of MS-DOS.
static bool CheckIsExecutable(string filePath)
{
//There\'s a #define for this value, named IMAGE_DOS_SIGNATURE.
var firstBytes = new byte[2];
using (var fileStream = File.Open(filePath, FileMode.Open))
{
fileStream.Read(firstBytes, 0, 2);
}
return Encoding.UTF8.GetString(firstBytes) == "MZ";
}