Check whether one specific process is running on windows with C++

前端 未结 3 2005
终归单人心
终归单人心 2020-12-11 21:02

Is there any function in psapi or windows.h to get desired process\' is running via only the process name (e.g : \"chrome.exe\") without getting all processes.

Edit

3条回答
  •  一向
    一向 (楼主)
    2020-12-11 21:39

    You can use CreateToolhelp32Snapshot as given above. If you need to regularly poll for the process, save the process ID once you've found it running and then check using OpenProcess. This is many times faster, but be aware that the OS recycles PIDs, so you'll have to deal with that.

    If you know something about the internals of the process (or even have control over it) there are other options such as checking for:

    • the existence of a named memory object (using CreateFileMapping)
    • the existence of a named mutex (using OpenMutex)

    More details are given in the answer to this question: Fast way to check for a specific process running

提交回复
热议问题