user2731777
user2731777

Reputation: 171

how to find path of exe

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

Answers (1)

Remy Lebeau
Remy Lebeau

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

Related Questions