求详细介绍Process32First这个API函数及其参数的用法
2个回答
2014-02-28
展开全部
process32First 是一个进程获取函数,当我们利用函数CreateToolhelp32Snapshot()获得当前运行进程的快照后,我们可以利用process32First函数来获得第一个进程的句柄.其原型为(用的是vfp) DECLARE INTEGER Process32First IN WIN32API ; INTEGER hSnapshot,STRING @ lppe 在C语言中如下 BOOL WINAPI Process32First( HANDLE hSnapshot, LPPROCESSENTRY32 lppe ); 此函数往往和 Process32Next( Handle hsnapShot, LPPROCESSENTRY32 lppe) 搭配使用,用来枚举当前系统快照相关的所有进程。 这些只是一点点,如有更好的解说,请告诉我,谢谢! vb实例 Private Type PROCESSENTRY32 dwSize As Long cntUseage As Long th32ProcessID As Long th32DefaultHeapID As Long th32ModuleID As Long cntThreads As Long th32ParentProcessID As Long pcPriClassBase As Long swFlags As Long szExeFile As String * 1024 End Type Private Sub demo() Dim MySnapHandle As Long Dim ProcessInfo As PROCESSENTRY32 MySnapHandle = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0) ProcessInfo.dwSize = Len(ProcessInfo) If Process32First(MySnapHandle, ProcessInfo) <> 0 Then '用来判断快照MySnapHandle 成功获得进程信息 end if end sub =============================================================================== C/C++ Code: PROCESSENTRY32 *info; // 在使用这个结构之前,先设置它的大小 info->dwSize = sizeof(PROCESSENTRY32 ); char proName[] = {"devenv.exe"}; HANDLE handlePro = NULL; //结束进程句柄 // 给系统内的所有进程拍一个快照 HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if(hProcessSnap == INVALID_HANDLE_VALUE) { printf(" CreateToolhelp32Snapshot调用失败! \n"); return -1; } // 遍历进程快照,轮流显示每个进程的信息 BOOL bMore = ::Process32First(hProcessSnap, info); BOOL terminate = FALSE; while( bMore != FALSE) { if(strcmp(proName,info->szExeFile) == 0) { handlePro=OpenProcess(PROCESS_TERMINATE, FALSE, info->th32ProcessID); if (NULL == handlePro) { break; } //结束进程 terminate = TerminateProcess(handlePro, 0); } bMore = Process32Next(hProcessSnap, info); } ::CloseHandle(hProcessSnap);
2014-02-28
展开全部
Process32First FunctionRetrieves information about the first process encountered in a system snapshot.BOOL WINAPI Process32First( __in HANDLE hSnapshot, __in_out LPPROCESSENTRY32 lppe);ParametershSnapshot A handle to the snapshot returned from a previous call to the CreateToolhelp32Snapshot function.lppe A pointer to a PROCESSENTRY32 structure. It contains process information such as the name of the executable file, the process identifier, and the process identifier of the parent process.Return ValueReturns TRUE if the first entry of the process list has been copied to the buffer or FALSE otherwise. The ERROR_NO_MORE_FILES error value is returned by the GetLastError function if no processes exist or the snapshot does not contain process information.RemarksThe calling application must set the dwSize member of PROCESSENTRY32 to the size, in bytes, of the structure. To retrieve information about other processes recorded in the same snapshot, use the Process32Next function.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询