如何找到打开程序的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.ToStringBut 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 nextGetProcessesByName 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).Idor
'Find all! for each proc in localByName Label1.Text &= proc.Id & vbCrLf 'vbCrlf just adds a new line for reading purposes next更多推荐
发布评论