遍历 进程

BOOL Crar2Dlg::FindProcess(CString ProcessName)
{
    HANDLE handle=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
    BOOL ret = FALSE;
    PROCESSENTRY32* info=new PROCESSENTRY32;//声明进程信息变量
    info->dwSize=sizeof(PROCESSENTRY32);   
    int i=0;
    if(Process32First(handle,info))
    {
        if(GetLastError()==ERROR_NO_MORE_FILES )
            return FALSE;
        else
        {
            CString id;
            id.Format(_T("%s"),info->szExeFile);
            if(ProcessName == id)
                ret = TRUE;
            if(ret == FALSE)
            {
                while(Process32Next(handle,info)!=FALSE)
                {
                    id.Format(_T("%s"),info->szExeFile);
                    if(id == ProcessName)
                    {
                        ret = TRUE;
                        break;
                    }
                    i++;
                }
            }
        }
    }
    else
        ret = FALSE;
    CloseHandle(handle);
    delete info;
    return ret;
}

 

posted @ 2012-08-26 09:01  瓜蛋  阅读(256)  评论(0编辑  收藏  举报