让我们说我正在尝试使用以下代码创建一个新进程:
- System.Diagnostics.Process p = new System.Diagnostics.Process();
- p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
- p.StartInfo.FileName = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\AwesomeFile.exe";
- p.StartInfo.Arguments = "parameter1 parameter2";
- p.StartInfo.CreateNoWindow = true;
- p.Start();
在下一行中,我将尝试使用以下行获取该进程的pid:
- MessageBox.Show(p.Id);
解决方法
做这个 System.Diagnostics.Process.GetProcessesByName( “processname”)[0] .ID.