GetModuleFileNameEx – Split output

I trying to get process name from the process id, and I’ve use GetModuleFileNameEx and I write this function.

char* ProcessName(ULONG_PTR ProcessId)
{
    char szBuffer[MAX_PATH+1];
    HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_TERMINATE, FALSE, ProcessId);

    if(GetModuleFileNameEx(hProcess, NULL, szBuffer, MAX_PATH) == 0)
        sprintf(szBuffer, "null");

    CloseHandle(hProcess);

    return szBuffer;
}

the output is Full-Path&Process-Name, and I want split it so I can get the process-name without Full-Path.

Is there any way to do this, or any other function can I use it to get process name from its process id?


Source: c++

Leave a Reply