如何在后台启动进程?
How can I start a process in the background?
我似乎无法在 Google 或此处的 Whosebug 上找到答案。
如何在后台启动进程(在活动 window 之后)?就像,当进程启动时,它不会中断用户正在使用的当前应用程序。
该进程不会在当前应用程序前面弹出,它只是启动。
这是我正在使用的:
Process.Start(Chrome.exe);
Chrome 在我的应用程序启动时弹出。如何让它在后台启动?
我也试过:
psi = new ProcessStartInfo ("Chrome.exe");
psi.UseShellExecute = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(psi);
但是和上一个完全没有区别
谢谢。
下面的代码应该可以满足您的需求:
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);
}
试试这个:
Process p = new Process();
p.StartInfo = new ProcessStartInfo("Chrome.exe");
p.StartInfo.WorkingDirectory = @"C:\Program Files\Chrome";
p.StartInfo.CreateNoWindow = true;
p.Start();
此外,如果这不起作用,请尝试添加
p.StartInfo.UseShellExecute = false;
我似乎无法在 Google 或此处的 Whosebug 上找到答案。
如何在后台启动进程(在活动 window 之后)?就像,当进程启动时,它不会中断用户正在使用的当前应用程序。
该进程不会在当前应用程序前面弹出,它只是启动。
这是我正在使用的:
Process.Start(Chrome.exe);
Chrome 在我的应用程序启动时弹出。如何让它在后台启动?
我也试过:
psi = new ProcessStartInfo ("Chrome.exe");
psi.UseShellExecute = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.WindowStyle = ProcessWindowStyle.Minimized;
Process.Start(psi);
但是和上一个完全没有区别
谢谢。
下面的代码应该可以满足您的需求:
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);
}
试试这个:
Process p = new Process();
p.StartInfo = new ProcessStartInfo("Chrome.exe");
p.StartInfo.WorkingDirectory = @"C:\Program Files\Chrome";
p.StartInfo.CreateNoWindow = true;
p.Start();
此外,如果这不起作用,请尝试添加
p.StartInfo.UseShellExecute = false;