i want to code an application that lists all currently running processes. here is my code :
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <Psapi.h>
int main(int argc, char *argv[])
{
int x;
int returned;
char module[100];
HANDLE hProcess;
char name[200];
HMODULE modules;
DWORD moduleBytesReturned;
DWORD prozesse[60],bytesReturned;
EnumProcesses(prozesse,sizeof(prozesse),&bytesReturned);
returned = bytesReturned/sizeof(DWORD);
for(x=0;x<returned;x++)
{
if((hProcess=OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,FALSE,prozesse[x]))==NULL)
printf("OpenProcessError:%d bei PID:%d \n",GetLastError(),prozesse[x]);
else
if((EnumProcessModules(hProcess,&modules,sizeof(modules),&moduleBytesReturned))==0)
printf("EnumProcessError:%d bei PID:%d \n",GetLastError(),prozesse[x]);
else
if((GetModuleBaseName(hProcess,modules,name,200))==0)
printf("GetModuleError:%d bei PID:%d \n",GetLastError(),prozesse[x]);
else
printf("%s\n",name);
}
system("PAUSE");
}
but when i run the program i get access denied errors at csrss.exe and at 2 instances of svchost.exe which are running as services.
what am i doing wrong ?
thanks for help
usch
