Start App with shell command - CSharp System.Diagnostics

CSharp examples for System.Diagnostics:Process

Description

Start App with shell command

Demo Code


using System.Diagnostics;

public class Main{

        public static bool StartApp(string appName, string arguments, ProcessWindowStyle style)
        {/*from www .j a va  2s .  c om*/
            bool blnRst = false;
            Process p = new Process();
            p.StartInfo.FileName = appName;//exe,bat and so on
            p.StartInfo.WindowStyle = style;
            p.StartInfo.Arguments = arguments;
            try
            {
                p.Start();
                p.WaitForExit();
                p.Close();
                blnRst = true;
            }
            catch
            {
            }
            return blnRst;
        }

        public static bool StartApp(string appName, string arguments)
        {
            return StartApp(appName, arguments, ProcessWindowStyle.Hidden);
        }

        public static bool StartApp(string appName, ProcessWindowStyle style)
        {
            return StartApp(appName, null, style);
        }

        public static bool StartApp(string appName)
        {
            return StartApp(appName, ProcessWindowStyle.Hidden);
        }
}

Related Tutorials