I need to make the primary .exe unrunnable from it (When you try to start it directly ,you get a message : Cannot start directly,if it runs from the secondary exe (only it,m
Set up the EXE that can't be started directly to accept a parameter, such as a SHA-256 hash of some unique data from the one that's supposed to start it. If that parameter doesn't exist or is not what's expected, display an error and exit.
EDIT:
static class Program
{
static void Main(params string[] args) //<- first needed change
{
if(args.Length == 0 || args[0] != "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855")
{
Console.WriteLine("Cannot execute this program directly.")
return;
}
... //rest of main function
}
}
Make the first exe a DLL. Then the second program can use it but a user won't be able to run it directly.
I am not sure if the process name (Process.GetCurrentProcess().ProcessName
) would give you the 1st or the second EXE name but you can make the 1st EXE as a DLL and the second as an EXE.
The simplest way to do that is to have command line parameters, or beter still, set an environment variable and run it, so theres little way to trace the requirements from a "can I get round the fact you want me to use your app to run it". However, I would say a DLL would be the way to go really.