]、。·ˉˇ¨〃々—~‖…’”〕〉》」』〗】∶!"'),.:;?]` #include <vcl.h>
#pragma hdrstop
#include "ListUnit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
#include <tlHelp32.h>
int ProcessID[1024]; // 存放进程标识号
void __fastcall TForm1::Button1Click(TObject *Sender)
{ // 显示进程列表
HANDLE ProcessListHandle=
CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
// 产生进程列表句柄
ListBox1->Items->Clear();
int i=0;
PROCESSENTRY32 ProcessStruct;
ProcessStruct.dwSize=sizeof(ProcessStruct);
int yn=Process32First(ProcessListHandle,
&ProcessStruct);
while (yn!=0)
{
ProcessID[i++]=ProcessStruct.th32ProcessID;
ListBox1->Items->Add(ProcessStruct.szExeFile);
yn=Process32Next(ProcessListHandle,&ProcessStruct);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{ // 强行中止进程
int i=ListBox1->ItemIndex;
if (i!=-1)
{
int pID=ProcessID[i];
HANDLE h=OpenProcess(PROCESS_ALL_ACCESS,true,pID);
DWORD ExitCode;
GetExitCodeProcess(h,&ExitCode); // 取中止码
TerminateProcess(h,ExitCode); // 强行中止
Sleep(100); // 延时100ms
Button1->Click(); // 重新列表
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Button1->Click();
}
int ModuleID[1024]; // 存放DLL标识号
void __fastcall TForm1::Button3Click(TObject *Sender)
{ // 显示某进程的所有DLL名
int i=ListBox1->ItemIndex;
if (i!=-1)
{
int pID=ProcessID[i]; // 列这个进程的DLL名
HANDLE ModuleListHandle=
CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,pID);
ListBox2->Items->Clear();
int j=0;
MODULEENTRY32 ModuleStruct;
ModuleStruct.dwSize=sizeof(ModuleStruct);
int yn=Module32First(ModuleListHandle,
&ModuleStruct);
while (yn!=0)
{
ModuleID[j++]=ModuleStruct.th32ModuleID;
ListBox2->Items->Add(ModuleStruct.szExePath);
yn=Module32Next(ModuleListHandle,&ModuleStruct);
}
}
}