There is a code
#define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <locale> #include <windows.h> #include <tlhelp32.h> VOID PrintProcessList(HANDLE CONST hStdOut) { PROCESSENTRY32 peProcessEntry; TCHAR szBuff[1024]; DWORD dwTemp; TCHAR filepath[MAX_PATH]; DWORD size = sizeof(filepath) / sizeof(TCHAR) - 1; HANDLE hproc; char text[MAX_PATH + 1]; HANDLE CONST hSnapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0); if (INVALID_HANDLE_VALUE == hSnapshot) { return; } bool tr; peProcessEntry.dwSize = sizeof(PROCESSENTRY32); Process32First(hSnapshot, &peProcessEntry); do { wsprintf(szBuff, L"=== %08X %s ===\r\n", peProcessEntry.th32ProcessID, peProcessEntry.szExeFile); WriteConsole(hStdOut, szBuff, lstrlen(szBuff), &dwTemp, NULL); hproc = OpenProcess(PROCESS_ALL_ACCESS, FALSE, peProcessEntry.th32ProcessID); printf("%i, ", GetLastError()); tr = QueryFullProcessImageNameW(hproc, 0, filepath, &size); printf("%i, %i\n", GetLastError(), tr); wcstombs(text, filepath, wcslen(filepath) + 1); puts(text); //printf("%s\n", filepath); } while (Process32Next(hSnapshot, &peProcessEntry)); CloseHandle(hSnapshot); } INT main() { setlocale(LC_ALL, "russian"); HANDLE CONST hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); PrintProcessList(hStdOut); system("pause"); ExitProcess(0); } Not for all processes, it shows the correct location (there are correct definitions).
Question: what am I doing wrong in the code? What needs to be changed so that the paths to the files (to all without exception) are determined correctly?
OpenProcess, not every process will allow it. Especially system processes. For such, you will have to plug up "holes" with if-s. - nick_n_a