进程中查、杀exe程序

 

对于非隐藏、有窗口名称的可以用:

 CWnd *pWnd = (CWnd*)FindWindow( NULL, _T("YourApp"));
 if(NULL != pWnd)
 {
  pWnd->PostMessage( WM_QUIT, 0, 0) ;

}

关闭exe

 

对隐藏的、或者没有窗口名称的exe用如下代码查、杀

    DWORD ProcessID[50];
    HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); 
    PROCESSENTRY32* info=new PROCESSENTRY32;
    PROCESSENTRY32 ProcessInfo;
    ProcessInfo.dwSize=sizeof(ProcessInfo);
    
    BOOL Status=Process32First(SnapShot,&ProcessInfo);
    int nProcess=0;
    while(Status)
    {
        CString s,str1,str2;
        s.Format("%d",ProcessInfo.cntThreads);
        str1.Format("%s",ProcessInfo.szExeFile);
        str1=ProcessInfo.szExeFile;
        ProcessID[nProcess]=ProcessInfo.th32ProcessID; 
        if(str1=="YourApp.exe")
        {
            HANDLE ProcessHandle;
            ProcessHandle=OpenProcess (PROCESS_ALL_ACCESS,FALSE,ProcessID[nProcess]);
            TerminateProcess(ProcessHandle,0); 
        }
        Status=Process32Next(SnapShot,&ProcessInfo); 

        nProcess++;

    } 

要包括头文件:#include "TLHELP32.H"

 

你可能感兴趣的:(查进程,关闭某个进程)