I'm trying to get the name of all my open processes. This is what I have:
#include "stdafx.h"
#include <Psapi.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR pCmdLine, int iCmdShow)
{
bool _result;
DWORD *pProcessIds = new DWORD[1000];
DWORD cb;
DWORD pBytesReturned;
_result = EnumProcesses(pProcessIds, 1000, &pBytesReturned);
HANDLE hndProccesse;
for (int i = 0; i < pBytesReturned / sizeof(DWORD); ++i)
{
hndProccesse = OpenProcess(STANDARD_RIGHTS_ALL, false, *pProcessIds);
DWORD _len;
DWORD _len2 =0;
LPWSTR lpFilename = new WCHAR[100];
_len =GetModuleFileNameEx(hndProccesse,NULL, lpFilename, _len2);
DWORD _errr;
_errr = GetLastError();
MessageBox(NULL, lpFilename, NULL, 0);
CloseHandle(hndProccesse);
pProcessIds ++;
}
return 0;
}
Everything is working fine upto GetModuleFileNameEx
which is giving an Access Denied Error (5).
Also this is whats displaying on the message box:
Any Ideas?