I have enumed the processIDs using EnumProcesses. I now want to find the name of the EXE file associated with each processID. How do I do this? I was thinking of GetProcessImageFileName at first, but that doesn't allow a processID as input. It expects an hProcess (handle to a process) as input. Yes I could use OpenProcess to convert the processID into an hProcess, but that seems like an extra unnecessary step. I would think that in the vast collection of Windows API functions available, there'd be one I could use to get the EXE file name, with the only input being the processID, as this would seem like a fairly common thing that one would want to do (find the name of the EXE file associated with a processID). But I can't find such an API function. Is there one that I'm just overlooking? Or do I really need to waste those extra lines of code with the OpenProcess and CloseHandle functions, just to get the name of the EXE file?
↧