C#-如何查找单独程序的进程id?
我需要计算机上已经运行的程序的进程ID。我该怎么做呢?(进程不是从process.Start()启动的)使用或仅使用一点LINQ,这取决于您打算如何识别程序C#-如何查找单独程序的进程id?,c#,.net,C#,.net,我需要计算机上已经运行的程序的进程ID。我该怎么做呢?(进程不是从process.Start()启动的)使用或仅使用一点LINQ,这取决于您打算如何识别程序 using System; using System.Diagnostics; using System.ComponentModel; void Example() { // Get all processes running on the local computer. var localProces
using System;
using System.Diagnostics;
using System.ComponentModel;
void Example()
{
// Get all processes running on the local computer.
var localProcesses = Process.GetProcesses();
//Get all processes with a name that contain "Foo" in the title
var fooProcess = localProcesses.Where(p => p.MainWindowTitle.Contains("Foo"));
// Get all instances of Notepad running on the local computer.
var notepad = Process.GetProcessesByName("notepad").Single();
}
拥有流程对象后,可以使用属性获取其ID
var id = process.Id;
我对这个答案感到困惑。我需要在PC上运行的进程的进程id。此示例没有显示任何有关将名称转换为id的内容。首先获取对象。从那里你可以得到你想要的。