I am building MFC Dialog Application.
I use Visual Studio 2010, MFC 2008/2010.
In my cpp file, i have some code to get info of the process. the process user name is SYSTEM
.
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,
FALSE, 0); // 0 is my process id
DWORD testerror = GetLastError();
// Get the process name.
if (NULL != hProcess )
{
HMODULE hMod;
DWORD cbNeeded;
if ( EnumProcessModules( hProcess, &hMod, sizeof(hMod),
&cbNeeded) )
{
GetModuleBaseName( hProcess, hMod, namestr,
sizeof(namestr)/sizeof(TCHAR) );
}
}
else
{
MessageBox(L"", L"", MB_OK);
}
CloseHandle();
Result is displaying MessageBox, because handle is NULL.
I get GetLastError() and it return 5 ( Access is denied).
I dont know why? Thanks a lot!
0 is my process id
, what does "my" mean? Is it the ID of another process or the current process? In the latter case, you don't need to open the process at all, you can just useGetCurrentProcess
. – Frerich Raabe