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.th32ParentProcessID 进程的父进程
杀死进程:
WINBASEAPI BOOL WINAPI TerminateProcess( __in HANDLE hProcess, __in UINT uExitCode );
HANDLE hProcess= OpenProcess( PROCESS_ALL_ACCESS, FALSE,ProcessInfo.th32ProcessID); if(::TerminateProcess(hProcess,1))