Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#-如何查找单独程序的进程id?_C#_.net - Fatal编程技术网

C#-如何查找单独程序的进程id?

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

我需要计算机上已经运行的程序的进程ID。我该怎么做呢?(进程不是从process.Start()启动的)

使用或仅使用一点LINQ,这取决于您打算如何识别程序

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的内容。首先获取对象。从那里你可以得到你想要的。