« 前一篇:UrlEscape
后一篇:RemovePath »

TermProcess @ 2/10/2006

技术类
此函数用于强制关闭程序进程,可用于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);
}
发布于 2/10/2006 11:47:51 | 评论:0

看帖要回帖...

categories
archives
links
statistics
  • 网志数:1168
  • 评论数:2011