Будет работать на Windows Vista и новее. Используется функция
QueryFullProcessImageName.
#include <windows.h>
#include <tlhelp32.h>
int _tmain(int argc, _TCHAR* argv[])
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE) {
while (Process32Next(snapshot, &entry) == TRUE) {
if (_tcsicmp(entry.szExeFile, _T("explorer.exe")) == 0) {
HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, entry.th32ProcessID);
if (hProcess) {
TCHAR path[MAX_PATH];
DWORD cchExeName = MAX_PATH;
if (QueryFullProcessImageName(hProcess, 0, path, &cchExeName) != 0) {
_tprintf(_T("%s\r\n"), path);
}
CloseHandle(hProcess);
}
}
}
}
CloseHandle(snapshot);
return 0;
}