C# 获取在C中使用ProcessStartInfo启动的进程id#

C# 获取在C中使用ProcessStartInfo启动的进程id#,c#,process,C#,Process,我需要借助ProcessStartInfo类获取新创建的进程的进程id 这是我的密码 ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.FileName = "chrome.exe"; startInfo.Arguments = "--app=http://www.google.com/"; Process p = new Process(); p.StartInfo = startInfo; p.Start(); Co

我需要借助ProcessStartInfo类获取新创建的进程的进程id 这是我的密码

ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "chrome.exe";
startInfo.Arguments = "--app=http://www.google.com/";
Process p = new Process();
p.StartInfo = startInfo;
p.Start();
Console.WriteLine(p.Id);
但是,它返回的ID不是进程chrome.exe进程的ID。我已经用不同的进程ID验证了PowerShell中是否存在chrome.exe进程


提前感谢。

Chrome将使用一个父进程创建多个子进程。当您从命令行运行Chrome时,您的新Chrome进程很可能会与现有Chrome进程(我猜是父进程)通信,然后退出,这解释了您看到的行为。

stackoverflow上的快速搜索-快速访问任务管理器将验证这一点。