简体   繁体   中英

How can I run a program from my C# program in hidden mode?

I would like to run a program in c#, silently (no window, trace, of the program being executed). How can I achieve this?

if you want run the whole project in hidden mode and it is a console application, just go to Project Properties and set Output type to Windows Application. thats it.

If you want to run some other program inside your main program in hidden mode you may use following code.

        string cmdText = "/c " + cmdStr;
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.StartInfo.CreateNoWindow = true;           
        proc.StartInfo.FileName = "cmd.exe";
        proc.StartInfo.Arguments = cmdText;
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardOutput = true;
        proc.StartInfo.RedirectStandardError = true;
        proc.Start();

the option which hide your console window is proc.StartInfo.CreateNoWindow = true;, and cmdStr is the command or programg you want to exeute.

If you want to run with a program with trace(notification icon in right bottom) means use NotifyIcon(In toolbox list is available) or if you want to run without any notification you need to go for service. This is the best guide for creating first service program Windows Service

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM