【问题标题】:How to find the PID of a open program如何找到打开程序的PID
【发布时间】:2016-10-30 12:25:50
【问题描述】:

我正在尝试找出如何找到 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 中还是很菜鸟,似乎在这里找不到问题。

【问题讨论】:

  • 昨天另一个用户提出了这个问题。有趣的是,这个问题再次由不同的用户名弹出......并且逐字逐句。

标签: vb.net process pid


【解决方案1】:

GetProcessesByName 返回一个数组。您可能有多个记事本在运行,但这里是获取第一个 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-31
    • 2014-07-01
    • 2020-07-14
    • 2023-03-26
    • 2019-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多