"iwdu15" <iw****@discussions.microsoft.com> schrieb im Newsbeitrag
news:6B**********************************@microsof t.com...
yes, but what parameters do i gve it?
Hi iwdu15,
a few years ago i wrote a procedure in C to kill processes:
#include "stdafx.h"
#include "endprog.h"
void main()
{
kill("proc1.exe");
kill("proc2.exe");
#ifdef _DEBUG
printf("Press Enter >");
_getch();
#endif
}
void kill(char* fName)
{ DWORD dProcID=0;
HWND hWnd=0;
while (dProcID=FindProcessID(fName))
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dProcID);
#ifdef _DEBUG
printf("Process %x;PID %u \n",hProcess,dProcID);
#endif
if(hProcess)
TerminateProcess(hProcess,0);
#ifdef _DEBUG
printf("%s killed \n",fName);
#endif
}
}
DWORD FindProcessID(char* szProcessName)
{
DWORD aProcesses[1024], cbNeeded, cProcesses;
unsigned int i;
if(!EnumProcesses(aProcesses,sizeof(aProcesses),&c bNeeded)) return 0;
cProcesses = cbNeeded/sizeof(DWORD);
for(i=0;i<cProcesses;i++)
{
if (CompareProcessNameandID( aProcesses[i],szProcessName))
return aProcesses[i];
}
return 0;
}
BOOL CompareProcessNameandID(DWORD processID, char* szSearchName)
{
char szProcessName[MAX_PATH] = "unknown";
HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ, FALSE, processID);
if (hProcess)
{
HMODULE hMod;
DWORD cbNeeded;
if(EnumProcessModules(hProcess,&hMod,sizeof(hMod), &cbNeeded))
GetModuleBaseName(hProcess,hMod,szProcessName,size of(szProcessName));
}
CloseHandle(hProcess);
return !_stricmp(szProcessName,szSearchName);
}
May be helpfull
B.R.
Klaus