How can I start a process in the background?

99封情书 提交于 2019-11-29 04:08:06
Tayla Wilson

Try this:

 Process p = new Process();
        p.StartInfo = new ProcessStartInfo("Chrome.exe");
        p.StartInfo.WorkingDirectory = @"C:\Program Files\Chrome";
        p.StartInfo.CreateNoWindow = true;
        p.Start();

Also, if that doesn't work, try adding

p.StartInfo.UseShellExecute = false;

Below code should do what you need:

class Program
{
    static void Main(string[] args)
    {
        var handle = Process.GetCurrentProcess().MainWindowHandle;
        Process.Start("Chrome.exe").WaitForInputIdle();
        SetForegroundWindow(handle.ToInt32());
        Console.ReadLine();
    }

    [DllImport("User32.dll")]
    public static extern Int32 SetForegroundWindow(int hWnd); 
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!