从pid或handle获取进程名称 [英] Get process name from pid or handle
本文介绍了从pid或handle获取进程名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我已经有一个窗口的句柄,则可以使用 GetWindowThreadProcessId
获取PID.有没有一种方法可以获取进程名称而不必获取所有进程并尝试匹配我的PID?
Assuming I already have the handle to a window, I can get the PID with GetWindowThreadProcessId
. Is there a way I can get the process name without having to get all the processes and try to match my PID?
推荐答案
您可以使用 Process.GetProcessById
获取 Process
. Process
具有许多有关正在运行的程序的信息. Process.ProcessName
为您提供名称, Process.MainModule.FileName
为您提供可执行文件的名称.
You can use Process.GetProcessById
to get Process
. Process
has a lot of information about the running program. Process.ProcessName
gives you the name, Process.MainModule.FileName
gives you the name of the executable file.
这篇关于从pid或handle获取进程名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文