How can I be sure that a file passed to my program is a valid exe file ?
actually my program takes a file as input and runs it, but user can input any file so I have
If you want to just check the file extension:
if (String.Equals(Path.GetExtension(filePath), ".exe", StringComparison.InvariantCultureIgnoreCase))
{
...
}
If you need to verify that the file is really executable you can analyze its header. There is information about .exe file header: link.
You also can try to run the file as 0xA3 suggested