QT_强杀进程
#ifdef WIN32 bool res = false; HANDLE hToolHelp32Snapshot; hToolHelp32Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); PROCESSENTRY32 pe = { sizeof(PROCESSENTRY32) }; BOOL isSuccess = Process32First(hToolHelp32Snapshot, &pe); while (isSuccess) { size_t len = WideCharToMultiByte(CP_ACP, 0, pe.szExeFile, wcslen(pe.szExeFile), NULL, 0, NULL, NULL); char *des = (char *)malloc(sizeof(char) * (len + 1)); WideCharToMultiByte(CP_ACP, 0, pe.szExeFile, wcslen(pe.szExeFile), des, len, NULL, NULL); des[len] = '\0'; if (!strcmp(des, appName.toStdString().c_str())) { appPath = getProcessPathForWin(pe.th32ProcessID); TerminateProcess(OpenProcess(PROCESS_TERMINATE, FALSE, pe.th32ProcessID), 0); res = true; } free(des); isSuccess = Process32Next(hToolHelp32Snapshot, &pe); } CloseHandle(hToolHelp32Snapshot); return res; #else QString killProcess = "killall appName";
int ret = system(QStringConvertChar(killProcess));
qDebug() << QString::fromStdString(getTime(1)) << "killProcess result:" << ret << "----" << killProcess; return ret == 0 ? true : false;
#endif
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
作者:风来风往风伤
出处:http://www.cnblogs.com/amwuau/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。