In Anlehnung an http://dotnet-snippets.de/dns/pruefen-ob-datei-eine-exe-datei-ist-SID539.aspx
public Boolean IsExecuteable(String aFileName)
{
if (File.Exists(aFileName))
{
try
{
FileStream FS = new FileStream(aFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
Byte[] Data = new Byte[4];
FS.Seek(128, SeekOrigin.Begin);
FS.Read(Data, 0, 5);
FS.Close();
if ((Data[0] == 80) & (Data[1] == 69) & (Data[2] == 0) & (Data[3] == 0) & (Data[4] == 76))
{
return true;
}
else
{
return false;
}
}
catch
{
return false;
}
}
else
{
return false;
}
}
3 Kommentare zum Snippet