首页 > 编程语言 > 详细

c++结束进程的程序

时间:2014-03-14 18:52:19      阅读:509      评论:0      收藏:0      [点我收藏+]
bubuko.com,布布扣
 1 //#include <winbase.h>
 2 #include <windows.h>
 3 #include <process.h>
 4 #include <Tlhelp32.h>
 5 #include <tchar.h>
 6 
 7 
 8 BOOL FindAndKillProcessByName(LPCTSTR strProcessName)
 9 {
10 if(NULL == strProcessName)
11 {
12 return FALSE;
13 }
14 
15 HANDLE handle32Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
16 
17 if (INVALID_HANDLE_VALUE == handle32Snapshot)
18 {
19 return FALSE;
20 }
21 
22 
23 
24 PROCESSENTRY32 pEntry;      
25 pEntry.dwSize = sizeof( PROCESSENTRY32 );
26 
27 
28 
29 //Search for all the process and terminate it
30 
31 if(Process32First(handle32Snapshot, &pEntry))
32 {
33 BOOL bFound = FALSE;
34 if (!_tcsicmp(pEntry.szExeFile, strProcessName))
35 {
36 bFound = TRUE;
37 }
38 while((!bFound)&&Process32Next(handle32Snapshot, &pEntry))
39 {
40 if (!_tcsicmp(pEntry.szExeFile, strProcessName))
41 {
42 bFound = TRUE;
43 }
44 }
45 if(bFound)
46 {
47 CloseHandle(handle32Snapshot);
48 HANDLE handLe =  OpenProcess(PROCESS_TERMINATE , FALSE, pEntry.th32ProcessID);
49 BOOL bResult = TerminateProcess(handLe,0);
50 return bResult;
51 }
52 }
53 CloseHandle(handle32Snapshot);
54 return FALSE;    
55 }
56 int main(){
57 
58 FindAndKillProcessByName("Notepad.exe");
59 return 0;
60 }
bubuko.com,布布扣

c++结束进程的程序,布布扣,bubuko.com

c++结束进程的程序

原文:http://www.cnblogs.com/ydxt/p/3598686.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!