C++ 判断进程是否存在

Bertha 。 2022-06-09 06:59 460阅读 0赞
  1. 原文出处:http://blog.csdn.net/zhensoft163/article/details/7967993
  2. #include <windows.h>
  3. #include "psapi.h"
  4. #include"stdio.h"
  5. #include <tlhelp32.h>
  6. //判断进程是否存在
  7. //2012-09-10
  8. BOOL FindProcess()
  9. {
  10. int i=0;
  11. PROCESSENTRY32 pe32;
  12. pe32.dwSize = sizeof(pe32);
  13. HANDLE hProcessSnap = ::CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  14. if(hProcessSnap == INVALID_HANDLE_VALUE)
  15. {
  16. i+=0;
  17. }
  18. BOOL bMore = ::Process32First(hProcessSnap, &pe32);
  19. while(bMore)
  20. {
  21. //printf(" 进程名称:%s \n", pe32.szExeFile);
  22. if(stricmp("进程名",pe32.szExeFile)==0)
  23. {
  24. //printf("进程运行中");
  25. i+=1;
  26. }
  27. bMore = ::Process32Next(hProcessSnap, &pe32);
  28. }
  29. if(i>1){ //大于1,排除自身
  30. return true;
  31. }else{
  32. return false;
  33. }
  34. }

发表评论

表情:
评论列表 (有 0 条评论,460人围观)

还没有评论,来说两句吧...

相关阅读