一个寻找进程函数

#include <tlhelp32.h>

 

BOOL CmfcFindProcDlg::FindCurProcess(CString strCurProcess)
{
 HANDLE hProcessSnap;
 HANDLE hProcess;
 PROCESSENTRY32 pe32;
 DWORD dwPriorityClass;
 CString strListProcName;
 BOOL res = FALSE;

 hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
 if( hProcessSnap == INVALID_HANDLE_VALUE )
 {
  AfxMessageBox(" CreateToolhelp32Snapshot error");
  return res;
 }
 pe32.dwSize = sizeof( PROCESSENTRY32 );
 if( !Process32First( hProcessSnap, &pe32 ) )
 {
  AfxMessageBox( TEXT("Process32First") ); // show cause of failure
  CloseHandle( hProcessSnap );          // clean the snapshot object
  return res;
 }
 do
 {
  strListProcName = pe32.szExeFile;
  if(strCurProcess == strListProcName )
  {
   AfxMessageBox("find exe OK!");
   res = TRUE;
   break;
  }

 }while(Process32Next( hProcessSnap, &pe32 ));

 CloseHandle( hProcessSnap );
 return res;
}

 

参考:

http://msdn.microsoft.com/en-us/library/ms686701(v=VS.85).aspx

你可能感兴趣的:(一个寻找进程函数)