Can't Get Module Name For Process Module

  • Thread starter Thread starter Tall_Guy_63
  • Start date Start date
T

Tall_Guy_63

Guest
LONG findprogram()
{
LONG count;
DWORD aProcesses[1024],cbNeeded,cProcesses,processID,CurrentProcessId,lpExitCode;
unsigned int i;
std::wstring szProcessName;
HANDLE hProcess;
HMODULE hMod;
std::string namepath="PROGRAMNAME.EXE";
std::string cmpnamepath;
std::wstring wtxt;

CurrentProcessId=GetCurrentProcessId();

if(!EnumProcesses(aProcesses,sizeof(aProcesses),&cbNeeded))
{
return 0;
}

cProcesses=cbNeeded/sizeof(DWORD);
count=1; //number of WenDuct processes running

for(i=0;i<cProcesses;i++)
{
if(aProcesses != 0)
{
processID=aProcesses;

if(processID == CurrentProcessId) //leave out current program
continue;

hProcess=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,processID);

if(hProcess)
{
WCHAR Buffer[MAX_PATH];

if(GetModuleFileNameEx(hProcess,NULL,Buffer,MAX_PATH))
{
szProcessName=Buffer;
}
}

showtextmessagew(szProcessName); //always blank

wtxt=szProcessName;
cmpnamepath=wstrtostr(wtxt);

if(ucase(cmpnamepath) == namepath)
{
count++;
GetExitCodeProcess(hProcess,&lpExitCode);
TerminateProcess(hProcess,lpExitCode);
}

CloseHandle(hProcess);
}
}

return count;
}

Continue reading...
 
Back
Top