How to hide a console application in C#

前端 未结 9 1867
刺人心
刺人心 2020-12-06 09:27

I have a console application in C#, and I want that the user won\'t be able to see it.

How can I do that?

9条回答
  •  日久生厌
    2020-12-06 10:10

    Create a console application "MyAppProxy" with following code, and put MyAppProxy in start up dir,

    public static void main(string[] args)
    {
       Process p = new Process("MyApp");
       ProcessStartUpInfo pinfo = new ProcessStartUpInfo();
       p.StartupInfo = pinfo;
       pinfo.CreateNoWindow = true;
       pinfo.ShellExecute = false;
    
       p.RaiseEvents = true;
    
       AutoResetEvent wait = new AutoResetEvent(false);
       p.ProcessExit += (s,e)=>{ wait.Set(); };
    
       p.Start();
       wait.WaitOne();
    }
    

    You may need to fix certain items here as I didnt check correctness of the code, it may not compile because some property names may be different, but hope you get the idea.

提交回复
热议问题