怎样在自己的程序中停止其他 进程???

解决方案 »

  1.   

    先用GetProcessList得到系统进程列表,更具进程的文件名得到进程ID,再用OpenProcess从ID得到该进程的HANDLE, 既可以使用TerminateProcess结束进程。
    #include <tlhelp32.h>
    BOOL GetProcessList()
    {
    HANDLE         hProcessSnap = NULL; 
        BOOL           bRet      = FALSE; 
        PROCESSENTRY32 pe32      = {0}; 

        //  Take a snapshot of all processes in the system. 

        hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); 

        if (hProcessSnap == INVALID_HANDLE_VALUE) 
            return (FALSE); 

        //  Fill in the size of the structure before using it. 

        pe32.dwSize = sizeof(PROCESSENTRY32); 

        //  Walk the snapshot of the processes, and for each process, 
        //  display information. 

        if (Process32First(hProcessSnap, &pe32)) 
        { 
            do 
            { 
                
    TRACE(pe32.szExeFile); // pe32.szExeFile即程序名
                      TRACE(pe32.th32ProcessID);  // 进程ID
             TRACE("\n");
            } 
            while (Process32Next(hProcessSnap, &pe32)); 
            bRet = TRUE; 
        } 
        else 
            bRet = FALSE;    // could not walk the list of processes 

        // Do not forget to clean up the snapshot object. 

        CloseHandle (hProcessSnap); 
        return (bRet); 
    }