Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I need to get the exact parent process name. I'll explain in detail with below example,

Example:

Parent process name : MyApp

I tried using "GetModuleBaseName" function, but it returns "myapp.exe".

With "GetModuleFileNameEx" function, it returns "(path)/myapp.exe"

With "GetProcessImageFileName" function, it returns "(path)/myapp.exe"


But I need exact process name "MyApp". How to get this?

What I have tried:

Example:

Parent process name : MyApp

I tried using "GetModuleBaseName" function, but it returns "myapp.exe".

With "GetModuleFileNameEx" function, it returns "(path)/myapp.exe"

With "GetProcessImageFileName" function, it returns "(path)/myapp.exe"
Posted
Updated 2-Aug-19 4:47am
Comments
Richard MacCutchan 2-Aug-19 7:57am    
The values returned from those function calls are the exact process names. I assume that MyApp is a class name in your source code, which has no connection to the name of the process.

1 solution

You are almost there. Call GetModuleBaseName first. Then call PathFindExtension and that will return a pointer to the ".exe" part. Place a null character at that address and you will be left with MyApp.
 
Share this answer
 
Comments
Piraisudan 8-Aug-19 7:52am    
Hi @Rick-York, I tried using GetModuleBaseName and PathFindExtension. But the PathFindExtension function returns the same value that we passed from GetModuleBaseName function. How can I get that exact parent process image file name? What I'm missing in the below example?


Example:

if (GetModuleBaseName(hProcess, NULL, lpBaseName, MAX_PATH))
{
//
}
if (PathFindExtension(lpBaseName))
{
//
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900