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?
You can Pinvoke a call to FindWindow() to get a handle to your window and then call ShowWindow() to hide the window OR Start your application from another one using ProcessStartInfo.CreateNoWindow
Compile it as a Windows Forms application. Then it won't display any UI, if you do not explicitly open any Windows.
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.
The best way is to start the process without window.
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.Arguments = "echo Hello!";
//either..
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
//or..
p.StartInfo.CreateNoWindow = true;
p.Start();
See other probable solutions -
Toggle Process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden at runtime
and,
Bring another processes Window to foreground when it has ShowInTaskbar = false
Create a wcf service and host it as per your need.
On ProjectProperties set Output Type as Windows Application.