1
die pid kill function
void __fastcall TFormMain::SpeedButton1Click(TObject *Sender)
{
try {
AnsiString str;
char *tmp;
int i;
i= ListBox1->ItemIndex;
if( i != -1){
AnsiString s;
tmp = new char[100];
s=ListBox1->Items->Strings[i];
strcpy(tmp,(char*)s.c_str());
tmp=strtok(tmp,"\t");
}
int id=atoi(tmp);
delete[] tmp;
HANDLE ps = OpenProcess(1,false,id);
if(ps){
if(!TerminateProcess(ps,-9)){
ShowMessage((AnsiString)"Could not end process specified!");
}
else{
ShowMessage((AnsiString)"Process successfully terminated!");
}
}
else{
ShowMessage((AnsiString)"Could not open process requested!");
}
}
catch(Exception &e)
{
ShowMessage("Please select a PID");
}
}
die pid function ...
bool __stdcall EnumProc(HWND hWnd,/*LPARAM*/long/*lp*/)
{
unsigned long* pPid; //LPDWORD
unsigned long result; //DWORD
void *hg; //HGLOBAL
unsigned long id;
if(hWnd==NULL)
return false;
hg = GlobalAlloc(GMEM_SHARE,sizeof(unsigned long));
pPid = (unsigned long *)GlobalLock(hg);
result = GetWindowThreadProcessId(hWnd,pPid);
if(result){
char title[110];
char className[95];
char totalStr[256];
GetClassName(hWnd,className,95);
GetWindowText(hWnd,title,110);
id=*pPid;
ultoa(id,totalStr,10);
strcat(totalStr,"\t");
if(title){
strcat(totalStr,title);
strcat(totalStr,"\t");
}
strcat(totalStr,className);
FormMain->ListBox1->Items->Add((AnsiString)totalStr);
}
else{
GlobalUnlock(hg);
GlobalFree(hg);
return false;
}
GlobalUnlock(hg);
GlobalFree(hg);
return true;
}