ibferoz
asked on
Getting process name from processid
How to get process name (.exe) if I have process ID?
This depends on whether you are using Win9x or NT/W2k - the latter one has 'GetModuleBaseName()'. See the sample code at http://support.microsoft.com/default.aspx?scid=kb;EN-US;q175030 ("HOWTO: Enumerate Applications Using Win32 APIs (Q175030)") on how to do that.
This should find exe file's name by process id. I didn't test it so I don't know does it actually work.
void GetProcessNameById(DWORD Id, char **buffer) {
PROCESSENTRY32 processEntry = { 0 };
HANDLE hSnapShot = CreateToolhelp32Snapshot(T H32CS_SNAP PROCESS, 0);
*buffer = NULL;
processEntry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapShot, &processEntry)) {
do {
if (processEntry.th32ProcessI D == Id) {
*buffer = (char *)malloc(strlen(processEnt ry.szExeFi le) + 1);
strcpy(buffer, processEntry.szExeFile);
break;
}
} while (Process32Next(hSnapShot, &processEntry));
}
CloseHandle(hSnapShot);
}
void GetProcessNameById(DWORD Id, char **buffer) {
PROCESSENTRY32 processEntry = { 0 };
HANDLE hSnapShot = CreateToolhelp32Snapshot(T
*buffer = NULL;
processEntry.dwSize = sizeof(PROCESSENTRY32);
if (Process32First(hSnapShot,
do {
if (processEntry.th32ProcessI
*buffer = (char *)malloc(strlen(processEnt
strcpy(buffer, processEntry.szExeFile);
break;
}
} while (Process32Next(hSnapShot, &processEntry));
}
CloseHandle(hSnapShot);
}
weicco,
that works on win9x only and is also mentioned in the article :o)
that works on win9x only and is also mentioned in the article :o)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.