当前位置: 代码迷 >> VC >> 关闭进程 CreateToolhelp32Snapshot,该如何解决
  详细解决方案

关闭进程 CreateToolhelp32Snapshot,该如何解决

热度:8645   发布时间:2013-02-25 00:00:00.0
关闭进程 CreateToolhelp32Snapshot
关闭名为"explorer.exe"进程,以下代码为什么没用?
  LPCTSTR c_szExplorer = _T("explorer.exe");
HANDLE handle;
PROCESSENTRY32 *FProcessEntry32 = {0};
handle = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE,0);
FProcessEntry32->dwSize = sizeof(FProcessEntry32);
if(Process32First(handle,FProcessEntry32))
{
do
{
if (_tcscmp(FProcessEntry32->szExeFile,c_szExplorer) == 0)
{
HANDLE hand;
hand = OpenProcess(PROCESS_ALL_ACCESS,FALSE,FProcessEntry32->th32ProcessID);
TerminateProcess(hand,0);
}
  }while(!Process32Next(handle,FProcessEntry32));
CloseHandle(handle);  
}

------解决方案--------------------------------------------------------
while(!Process32Next(handle,FProcessEntry32)); 

你是 !Process32Next 的时候进行:
if (_tcscmp(FProcessEntry32->szExeFile,c_szExplorer) == 0) 

HANDLE hand; 
hand = OpenProcess(PROCESS_ALL_ACCESS,FALSE,FProcessEntry32->th32ProcessID); 
TerminateProcess(hand,0); 
}

当然没用.感觉像你把西瓜排除在外,买西瓜,当然买不到了哦.