TermProcess
此函数用于强制关闭程序进程,可用于win98及以上版本。
VOID TermProcess(LPCSTR lpszProcName) {
if(lpszProcName == NULL) {
return;
}
HANDLE hSnapProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(hSnapProcess == NULL) {
return;
}
PROCESSENTRY32 proc;
proc.dwSize = sizeof(PROCESSENTRY32);
BOOL bRet = Process32First(hSnapProcess, &proc);
while(bRet) {
CHAR* strExeFile = strupr(proc.szExeFile);
CHAR* strProcName = strupr(strdup(lpszProcName));
if(strstr(strExeFile, strProcName) != NULL) {
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, proc.th32ProcessID);
if(hProcess == NULL) {
continue;
} else {
TerminateProcess(hProcess, 0);
CloseHandle(hProcess);
}
}
bRet = Process32Next(hSnapProcess, &proc);
delete[] strProcName;
}
CloseHandle(hSnapProcess);
}