您好!
小弟是用關閉執行緒的方式,不知是否為您要的!
//--------------------------------------------------------------------------- #include
#pragma hdrstop /* 執行緒 */
#include
DWORD WinHandle[255];
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender)
{
PROCESSENTRY32 *ProcessEntry32=new PROCESSENTRY32;
HANDLE AHandle;
LPWSTR APath;
bool isFound;
int i;
String p,h;
i=0;
ListBox1->Items->Clear();
AHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
isFound = true;
try
{
ProcessEntry32->dwSize = sizeof(PROCESSENTRY32);
isFound = Process32First(AHandle, ProcessEntry32);
while(isFound)
{
OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ,
false, ProcessEntry32->th32ProcessID);
WinHandle[i ] = ProcessEntry32->th32ProcessID;
p = ProcessEntry32->szExeFile;
ListBox1->Items->Add(p);
isFound = Process32Next(AHandle, ProcessEntry32);
}
}
catch ( ... )
{
}
}
//--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender)
{
HANDLE AhProcess;
DWORD test;
test=WinHandle[ListBox1->ItemIndex];
AhProcess = OpenProcess(PROCESS_ALL_ACCESS, true, test);
TerminateProcess(AhProcess, 0);
ListBox1->Refresh();
}
//---------------------------------------------------------------------------