如何查看 Windows 上是否正在运行另一个进程?

如何查看 Windows 上是否正在运行另一个进程?

问题描述:

我有一个 VC++ 控制台应用程序,我需要检查是否有另一个进程正在运行.我没有窗口标题,我只有可执行文件名称.我如何获得它的进程句柄/PID?我可以枚举使用此 .exe 运行的进程吗?

I have a VC++ console app and I need to check to see if another process is running. I don't have the window title, all I have is the executable name. How do I get the process handle / PID for it? Can I enumerate the processes running with this .exe ?

您可以使用 EnumProcesses 枚举系统上的进程.

You can use EnumProcesses to enumerate the processes on a system.

您需要使用 OpenProcess 来获取进程句柄,然后 QueryFullProcessImageName 以获得可执行的进程.

You'll need to use OpenProcess to get a process handle, then QueryFullProcessImageName to get the processes executable.