I want to use pid to get the full path of the process.
#include <psapi.h>
HANDLE processHandle = NULL;
TCHAR filename[MAX_PATH];
processHandle = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, nPID);
if (processHandle != NULL)
{
if (GetModuleFileNameEx(processHandle, NULL, filename, MAX_PATH) == 0)
{
//fail to get module file name
}
else
{
//module file name : filename
}
CloseHandle(processHandle);
}
else
{
//fail to open process
}
This is the code that gets the path of the process using pid.
However, when I execute it, the following error occurs.
( I am using visual c ++ 6.0. )
Linking...
Process01Dlg.obj : error LNK2001: unresolved external symbol _GetModuleFileNameExA@16
Debug/Process01.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
- QueryFullProcessImageName
- GetModuleFileName
- GetModuleFileNameEx
- GetProcessImageFileName
All of the above methods have caused an error.
Is this a problem with the version?
Please answer. Thank you :)
It seems you forget to link your product with the
psapi.lib. Add it to the project dependencies.Not sure it would work in VC6.0.
However MSDN recommends other functions for retrieving process names: