如何找到打开程序的PID(How to find the PID of a open program)

编程入门 行业动态 更新时间:2024-10-15 14:20:16
如何找到打开程序的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中相当noob,似乎无法在这里找到问题。

I am trying to figure out how to find the PID, of for example notepad.exe. I have googled this, and I found lots of stuff, but I can't quite unterstand it. I've tried this code:

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

But when executed, I get system.diagnostics.process[] as output in label1. I am quite noob in vb.net still, and can't seem to find the problem here.

最满意答案

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

GetProcessesByName returns an array. You may have multiple Notepads running, but here is how you'd get the id of the first.

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

or

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

更多推荐

本文发布于:2023-08-05 21:37:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1437895.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:程序   PID   find   open   program

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!