C# : Making an exe to not run directly

强颜欢笑 提交于 2019-12-17 19:57:23

问题


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,must have a crc verification i think) then start .

Hope i make myself clear First .exe can't start directly Second .exe can start the first exe (only)


回答1:


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
   }
}



回答2:


Make the first exe a DLL. Then the second program can use it but a user won't be able to run it directly.




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/12479168/c-sharp-making-an-exe-to-not-run-directly

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!