C++ Windows - How to get process path from its PID

后端 未结 5 2280
挽巷
挽巷 2020-11-29 04:26

How can I retrieve a process\'s fully-qualified path from its PID using C++ on Windows?

5条回答
  •  無奈伤痛
    2020-11-29 04:49

    I didn't have very much luck with GetModuleFileNameEx and QueryFullProcessImageName is only available on Vista or higher. I was however able to get the path for a process by using GetProcessImageFilename. It returns the windows kernel path but you can use QueryDosDevice to compare the device path returned by GetProcessImageFilename with its proper drive path.

    This page shows how to normalize an windows kernel path returned by GetProcessImageFilename (see NormalizeNTPath function):

    http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/c48bcfb3-5326-479b-8c95-81dc742292ab/

提交回复
热议问题