永发信息网

VC如何强制结束程序进程

答案:3  悬赏:0  手机版
解决时间 2021-02-10 22:57
  • 提问者网友:不爱我么
  • 2021-02-10 06:51
RT
最佳答案
  • 五星知识达人网友:洎扰庸人
  • 2021-02-10 07:30
void KillProcess(TCHAR target[])
{
DWORD aps[1024], cbNeeded, cbNeeded2, i;
TCHAR buffer[256];
BOOL killed;
HANDLE hProcess;
HMODULE hModule;

killed = FALSE;

EnumProcesses(aps, sizeof(aps), &cbNeeded) for(i = 0; i < cbNeeded/sizeof(DWORD); ++i)
{
if(!(hProcess = OpenProcess(PROCESS_TERMINATE |
PROCESS_QUERY_INFORMATION |
PROCESS_VM_READ,FALSE, aps[i])))
continue;
if(!EnumProcessModules(hProcess, &hModule,
sizeof(hModule), &cbNeeded2))
continue;
GetModuleBaseNameA(hProcess, hModule, buffer, 256);
if(lstrcmpi(buffer, target) == 0)
{
if(TerminateProcess(hProcess, 0))
killed = TRUE;
CloseHandle(hProcess);
break;
}
CloseHandle(hProcess);
}
}
全部回答
  • 1楼网友:低血压的长颈鹿
  • 2021-02-10 10:06
如果代码实现的话可以这么写: void KillProcess(TCHAR target[]) {     DWORD aps[1024], cbNeeded, cbNeeded2, i;     TCHAR buffer[256];     BOOL killed;     HANDLE hProcess;     HMODULE hModule;     killed = FALSE;     EnumProcesses(aps, sizeof(aps), &cbNeeded)    for(i = 0; i < cbNeeded/sizeof(DWORD); ++i)     {         if(!(hProcess = OpenProcess(PROCESS_TERMINATE |                                     PROCESS_QUERY_INFORMATION |                                     PROCESS_VM_READ,FALSE, aps[i])))             continue;         if(!EnumProcessModules(hProcess, &hModule,                                 sizeof(hModule), &cbNeeded2))             continue;         GetModuleBaseNameA(hProcess, hModule, buffer, 256);         if(lstrcmpi(buffer, target) == 0)         {             if(TerminateProcess(hProcess, 0))                 killed = TRUE;             CloseHandle(hProcess);             break;         }         CloseHandle(hProcess);     } }
  • 2楼网友:蓝房子
  • 2021-02-10 08:39
如果代码实现的话可以这么写: void KillProcess(TCHAR target[]) {     DWORD aps[1024], cbNeeded, cbNeeded2, i;     TCHAR buffer[256];     BOOL killed;     HANDLE hProcess;     HMODULE hModule;     killed = FALSE;     EnumProcesses(aps, sizeof(aps), &cbNeeded)    for(i = 0; i < cbNeeded/sizeof(DWORD); ++i)     {         if(!
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯