Reputation: 171
I have a service (lets say myservice) which tries to find out path of another application (lets say myapp.exe). myservice only knows about the name of application not the full path. my code is as follow:
HMODULE hModule = GetModuleHandle(TEXT("myapp.exe"));
if( hModule == NULL )
{
// error 126
return false;
}
int ret = GetModuleFileName(hModule, szBuffer, dwBufferSize);
if( !ret )
{
.......
return false;
}
GetModuleHandle always returns with 126 error mod_not_found. how can ! achieve this functionality.
Thanks, KM.
Upvotes: 2
Views: 920
Reputation: 598114
You need to enumerate running processes using EnumProcesses()
, calling OpenProcess()
and GetModuleFileNameEx()
on each process ID until you find the filename you are interested in, then you will have its full path.
Upvotes: 2