return 0, Error Code 6, OpenProcess() in c++

135 Views Asked by At

Finding the paths of all currently running processes.

I am using mfc and I have also implemented a source for elevation.

Some of the paths are known, but about 50 out of 100 processes are returning 0 from the OpenProcessHandle. The error code is 6.

HANDLE hProcess;
TCHAR pPath[MAX_PATH];

hProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
pe32.dwSize = sizeof(PROCESSENTRY32);
SetPrivilege(hProcess, SE_DEBUG_NAME, TRUE);
if (Process32First(hProcess, &pe32)) {
    do {
        DWORD dwSize2 = MAX_PATH;
        memset(pPath, 0, sizeof(pPath));
        HANDLE htmp = OpenProcess(PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, pe32.th32ProcessID);
    CloseHandle(htmp);
    } while (Process32Next(hProcess, &pe32));
}
0

There are 0 best solutions below