如何找到打开程序的PID

How to find the PID of a open program

我想知道如何找到 PID,例如 notepad.exe。我用谷歌搜索了这个,我发现了很多东西,但我不太明白。我试过这段代码:

Dim currentProcess As Process = Process.GetCurrentProcess()
Dim localAll As Process() = Process.GetProcesses()
Dim localByName As Process() = Process.GetProcessesByName("notepad")
Label1.Text = localByName.ToString 

但是在执行时,我得到 system.diagnostics.process[] 作为 label1 中的输出。我在 vb.net 仍然很菜鸟,似乎无法在这里找到问题。

GetProcessesByName returns 一个数组。您可能有多个记事本 运行,但这是获取第一个记事本 ID 的方法。

Dim currentProcess As Process = Process.GetCurrentProcess()
Dim localAll As Process() = Process.GetProcesses()
Dim localByName As Process() = Process.GetProcessesByName("notepad")

'Do this
Label1.Text = localByName(0).Id

'Find all!
for each proc in localByName
   Label1.Text &= proc.Id & vbCrLf 'vbCrlf just adds a new line for reading purposes
next