kill process

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hi, im been working on a process manager for awhile and i cant find anywhere
how to kill a running process....any help would b awsome
 
Process.Kill() method
or
TerminateProcesS() Win32 API function.

hi, im been working on a process manager for awhile and i cant find anywhere
how to kill a running process....any help would b awsome
 
Process.Kill() kills the process represented by the current Process
instance. Process instance for the running processes could be obtained using
Process.GetProcesses().

For TerminateProcess(), pass the Process.Handle (obtained using
GetProcesses()) and an exit code.

yes, but what parameters do i gve it?
 
iwdu15 said:
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),&cbNeeded)) return 0;
cProcesses = cbNeeded/sizeof(DWORD);
for(i=0;i<cProcesses;i++)
{
if (CompareProcessNameandID( aProcesses,szProcessName))
return aProcesses;
}
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,sizeof(szProcessName));
}
CloseHandle(hProcess);
return !_stricmp(szProcessName,szSearchName);
}

May be helpfull
B.R.
Klaus
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top