当前位置: 动力学知识库 > 问答 > 编程问答 >

visual c++ - Not able to close the process

问题描述:

I am not able to close the process nb.exe. I need to close this process but it is not getting closed. During closing I also need to ensure that all the dll are unloaded related to this process. Below is my code.

bool ProcessExit(void)

{

PROCESSENTRY32 entry;

entry.dwSize = sizeof(PROCESSENTRY32);

HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);

if (Process32First(snapshot, &entry) == TRUE)

{

while (Process32Next(snapshot, &entry) == TRUE)

{

if (wcsicmp(entry.szExeFile, L"nb.exe") == 0)

{

HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, entry.th32ProcessID);

ExitProcess(entry.th32ProcessID);

CloseHandle(hProcess);

}

}

}

CloseHandle(snapshot);

return 1;

}

Please let me know if you have any inputs.

网友答案:

I think you are mistaken as to what ExitProcess(value) does. You are not doing anything to the process running nb.exe, but are exiting the current process with nb's process ID as the exit code.

分享给朋友:
您可能感兴趣的文章:
随机阅读: