有一个已经运行的进程。在任务管理器中名字为"abc.exe".
我想使用另外一个进程结束掉它。
想使用PostMessage(handle,msg,0,0)这个函数。
可是我不知道怎么获得那个进程的句柄。
帮帮忙,各位。

解决方案 »

  1.   

    //根据进程名称得到进程的ID,如果有多个实例在同时运行的话,只返回第一个枚举到的进程ID
    DWORD processNameToId(LPCTSTR lpszProcessName)
    {
       HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
       PROCESSENTRY32 pe;
       pe.dwSize = sizeof(PROCESSENTRY32);   if (!Process32First(hSnapshot, &pe)) {
           MessageBox(NULL, 
               "The frist entry of the process list has not been copyied to the buffer", 
               "Notice", MB_ICONINFORMATION | MB_OK);
           return 0;
       }    while (Process32Next(hSnapshot, &pe)) {
            if (!strcmp(lpszProcessName, pe.szExeFile)) {
                return pe.th32ProcessID;
            }
        }
     
        return 0;
    }
    根据abc.exe得到这个进程ID后,再
    HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcessId);就是 你要的了