简单办法:FindWindow();复杂点儿的:查找系统中相应的进程

解决方案 »

  1.   

    //enum process to find a certain module
    void CPtbView::IsAppRun(CString modulename)
    {
    DWORD buf[4096];
    DWORD num;
    TCHAR filenamebuf[_MAX_PATH+1];
    HMODULE hModule;
    DWORD cbReturned;
    BOOL bret=EnumProcesses(buf,4095,&num);
    bool bfound=false;
    CString msg;

    if(!bret)
    {
    AfxMessageBox("Error EnumProcesses");
    return;
    }

    for(int i=0;i<(int)num;i++)
    {
    HANDLE hProcess =OpenProcess(PROCESS_QUERY_INFORMATION&brvbar; PROCESS_VM_READ,false,buf[i]);
    if(hProcess ==NULL)
    continue;
    bret=EnumProcessModules(hProcess ,&hModule, sizeof(hModule), &cbReturned );
    if(bret)
    {
    DWORD dwret=GetModuleFileNameEx(hProcess ,hModule,filenamebuf,_MAX_PATH);
    CloseHandle( hProcess  ) ;
    if(dwret==0)
    {
    msg.Format("%d",GetLastError());
    AfxMessageBox(msg);
    break;
    }
    else
    {
    TCHAR* pfind=_tcsstr(filenamebuf,modulename);
    if(pfind)
    {
    bfound=true;
    break;
    }
    }
    }
    }
    if(bfound)
    AfxMessageBox("Found it");
    else
    AfxMessageBox("Not found");
    }void CPtbView::OnViewCheckrun()
    {
    IsAppRun("notepad.exe");
    }
      

  2.   

    also refer to 
    http://www.codeguru.com/system/PList.html
    Single interface for enumerating processes and modules under NT and Win9x/2K. - Ivo Ivanov (2001/10/04)