在WIN
Process
//
#ifndef Unit
#define Unit
//
#include
#include
#include
#include
#define TH
#define PROCESS_HANDLE_NAME
//
typedef struct tagPROCESSENTRY
{
DWORD dwSize;
DWORD cntUsage;
DWORD th
DWORD th
DWORD th
DWORD cntThreads;
DWORD th
LONG pcPriClassBase;
DWORD dwFlags;
TCHAR szExeFile[MAX_PATH]; //進程文件名
} PROCESSENTRY
typedef PROCESSENTRY
//以下定義要從KERENL
HANDLE (WINAPI *CreateToolhelp
BOOL (WINAPI *Process
BOOL (WINAPI *Process
//以下定義要從PSAPI
BOOL (WINAPI *EnumProcesses)(DWORD* lpidProcess
DWORD (WINAPI *GetModuleFileNameExA)(HANDLE hProcess
class TForm
{
__published: // IDE
TButton *FindAllProcessFileName;
TListBox *ListBox
void __fastcall FindAllProcessFileNameClick(TObject *Sender);
void __fastcall FormResize(TObject *Sender);
void __fastcall Button
void __fastcall ListBox
private: // User declarations
public: // User declarations
__fastcall TForm
};
//
extern PACKAGE TForm
//
#endif
Process
//
#include
#pragma hdrstop
#include
//
#pragma package(smart_init)
#pragma resource
TForm
//定義變量
HANDLE process[
PROCESSENTRY
DWORD process_ids[
DWORD num_processes;
TCHAR file_name[MAX_PATH];
TCHAR class_name[MAX_PATH];
unsigned i;
//
//初始化TOOLHELP
BOOL InitToolHelp
{
//動態調用
HINSTANCE DLLinst=LoadLibrary(
if(DLLinst)
{
//取各函數在KERNEL
CreateToolhelp
GetProcAddress(DLLinst
Process
GetProcAddress(DLLinst
Process
GetProcAddress(DLLinst
if((!(UINT)CreateToolhelp
return FALSE;
else
return TRUE;
}
return FALSE;
}
//初始化PSAPI
BOOL InitPSAPI()
{
HINSTANCE PSAPI=LoadLibrary(
if(NULL==PSAPI)
return FALSE;
EnumProcesses=(BOOL(WINAPI *)(DWORD* lpidProcess
GetProcAddress(PSAPI
GetModuleFileNameExA=(DWORD(WINAPI *)(HANDLE hProcess
GetProcAddress(PSAPI
if(NULL == EnumProcesses||NULL == GetModuleFileName)
return FALSE;
else
return TRUE;
}
__fastcall TForm
: TForm(Owner)
{
}
//
void __fastcall TForm
{
OSVERSIONINFO osinfo;
osinfo
//取當前操作系統類型
if(GetVersionEx(&osinfo))
{
switch(osinfo
{
//當前操作系統是WIN
case VER_PLATFORM_WIN
if(InitToolHelp
{
ListBox
p
//初始化TOOLHELP
HANDLE pName=CreateToolhelp
//開始查找
BOOL Next=Process
i=
//遍歷進程
while(Next)
{
//顯示進程
ListBox
//根據進程ID獲取句並
process[i]=OpenProcess(PROCESS_TERMINATE
//繼續查找
Next=Process
i++;
}
CloseHandle(pName);
}
break;
//當前操作系統是NT
case VER_PLATFORM_WIN
if(InitPSAPI())
{
ListBox
//獲取當前進程個數
EnumProcesses(process_ids
//遍歷進程
for(i=
//根據進程ID獲取句並
process[i]=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_READ
//通過句並獲取進程文件名
if(GetModuleFileNameExA(process[i]
ListBox
}
}
break;
}
}
}
//
void __fastcall TForm
{
int iCount;
iCount=ListBox
ListBox
}
//
else ShowMessage(
}
From:http://tw.wingwit.com/Article/os/xtgl/201311/9444.html