windows编程->进程获取


HANDLE定义:

typedef void *HANDLE;


PROCESSENTRY32 ProcessInfo;//定义进程信息变量

其定义如下:

typedef struct tagPROCESSENTRY32
{
    DWORD   dwSize;
    DWORD   cntUsage;
    DWORD   th32ProcessID;          // this process
    ULONG_PTR th32DefaultHeapID;
    DWORD   th32ModuleID;           // associated exe
    DWORD   cntThreads;
    DWORD   th32ParentProcessID;    // this process's parent process
    LONG    pcPriClassBase;         // Base priority of process's threads
    DWORD   dwFlags;
    CHAR    szExeFile[MAX_PATH];    // Path
} PROCESSENTRY32;
为了获取系统中的第一个线程和下一个要用到两个函数:

BOOL
WINAPI
Process32First(
    HANDLE hSnapshot,
    LPPROCESSENTRY32 lppe
    );

BOOL
WINAPI
Process32Next(
    HANDLE hSnapshot,
    LPPROCESSENTRY32 lppe
    );

ProcessInfo.th32ProcessID    进程ID

ProcessInfo.th32ParentProcessID  进程的父进程


杀死进程:

WINBASEAPI
BOOL
WINAPI
TerminateProcess(
    __in HANDLE hProcess,
    __in UINT uExitCode
    );
HANDLE hProcess= OpenProcess( PROCESS_ALL_ACCESS, FALSE,ProcessInfo.th32ProcessID);
				if(::TerminateProcess(hProcess,1))

实现方式如上。







你可能感兴趣的:(windows编程->进程获取)