By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,771 Members | 1,763 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,771 IT Pros & Developers. It's quick & easy.

kill process

P: n/a
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
--
-iwdu15
Nov 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Process.Kill() method
or
TerminateProcesS() Win32 API function.

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:B2**********************************@microsof t.com...
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
--
-iwdu15
Nov 23 '05 #2

P: n/a
yes, but what parameters do i gve it?
Nov 23 '05 #3

P: n/a
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.

"iwdu15" <iw****@discussions.microsoft.com> wrote in message
news:6B**********************************@microsof t.com...
yes, but what parameters do i gve it?
Nov 23 '05 #4

P: n/a

"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
Nov 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.