autorun.txt
上传用户:q88shop
上传日期:2022-07-12
资源大小:2k
文件大小:6k
源码类别:

杀毒

开发平台:

Visual C++

  1. 1. // Antivirus_Console.cpp : Defines the entry point for the console application.    
  2. 2. //    
  3. 3.    
  4. 4. #include "stdafx.h"    
  5. 5. #include "PSAPI.H"    
  6. 6. #include "Tlhelp32.h"    
  7. 7. BOOL OnFindProcess(CString ProcessName, bool b_kill);   
  8. 8. HANDLE OnCreateCMDFile();   
  9. 9. int _tmain(int argc, _TCHAR* argv[])   
  10. 10. {   
  11. 11.     LPWSTR m_filename = _T("Antivirus.bat");   
  12. 12.     BOOL m_append = TRUE;   
  13. 13.     HANDLE hCMDfile = CreateFile(   
  14. 14.         m_filename,  GENERIC_WRITE, FILE_SHARE_READ, NULL,   
  15. 15.         OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL  );   
  16. 16.    
  17. 17.     if ( hCMDfile == INVALID_HANDLE_VALUE) {   
  18. 18.         // We should throw an exception here    
  19. 19.         MessageBox(NULL,_T("Error open .bat file"),_T("Error"),MB_OK);   
  20. 20.     }   
  21. 21.     if (m_append) {   
  22. 22.         SetFilePointer( hCMDfile, 0, NULL, FILE_END );   
  23. 23.     } else {   
  24. 24.         SetEndOfFile( hCMDfile );   
  25. 25.     }   
  26. 26.        
  27. 27.     char *line = "Hello!nr test";   
  28. 28.     DWORD bytesWritten;   
  29. 29.     WriteFile(hCMDfile, line, strlen(line), &bytesWritten, NULL);   
  30. 30.     CloseHandle(hCMDfile);   
  31. 31.        
  32. 32.     OnFindProcess(_T("RavMonE.exe"),TRUE);   
  33. 33.     return 0;   
  34. 34. }   
  35. 35.    
  36. 36. BOOL OnFindProcess(CString ProcessName, bool b_kill)   
  37. 37. {   
  38. 38.     CString left6str_processname;   
  39. 39.     if (ProcessName.GetLength() > 6)   
  40. 40.         left6str_processname = ProcessName.Left(6);   
  41. 41.     DWORD ProcessID[10000];   
  42. 42.     HANDLE SnapShot=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);    
  43. 43.     PROCESSENTRY32 ProcessInfo;   
  44. 44.     ProcessInfo.dwSize=sizeof(ProcessInfo);       
  45. 45.     bool b_find = false;   
  46. 46.     try{   
  47. 47.         BOOL Status = Process32First(SnapShot,&ProcessInfo);   
  48. 48.         int m_nProcess = 0;    
  49. 49.         while(Status)   
  50. 50.         {   
  51. 51.             CString str1;   
  52. 52.             str1.Format(_T("%s"),ProcessInfo.szExeFile);   
  53. 53.             ProcessID[m_nProcess]=ProcessInfo.th32ProcessID;    
  54. 54.             if (ProcessName.Find(_T("."), 0) > 0)   
  55. 55.             {   
  56. 56.                 if(str1.CompareNoCase(ProcessName) == 0 || str1.Left(str1.Find(_T("."), 0)).CompareNoCase(ProcessName.Left(ProcessName.Find(_T("."), 0))) == 0)//***.exe就是你要结束的进程的名称    
  57. 57.                 {   
  58. 58.                     if (!b_kill)   
  59. 59.                     {   
  60. 60.                         b_find = true;   
  61. 61.                         goto Skip1;   
  62. 62.                     }   
  63. 63.                     else   
  64. 64.                     {   
  65. 65.                         HANDLE ProcessHandle;   
  66. 66.                         ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, ProcessID[m_nProcess]);   
  67. 67.                         TerminateProcess(ProcessHandle, 0);   
  68. 68.                         if (ProcessHandle)   
  69. 69.                         {   
  70. 70.                             CloseHandle(ProcessHandle);   
  71. 71.                             ProcessHandle = NULL;   
  72. 72.                         }   
  73. 73.                     }   
  74. 74.                 }   
  75. 75.                 if (str1.GetLength() > 6 && ProcessName.GetLength() > 6)   
  76. 76.                 {   
  77. 77.                     if(str1.Left(6).CompareNoCase(left6str_processname) == 0)   
  78. 78.                     {   
  79. 79.                         if (!b_kill)   
  80. 80.                         {   
  81. 81.                             b_find = true;   
  82. 82.                             goto Skip1;   
  83. 83.                         }   
  84. 84.                         else   
  85. 85.                         {   
  86. 86.                             HANDLE ProcessHandle;   
  87. 87.                             ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, ProcessID[m_nProcess]);   
  88. 88.                             TerminateProcess(ProcessHandle, 0);   
  89. 89.                             if (ProcessHandle)   
  90. 90.                             {   
  91. 91.                                 CloseHandle(ProcessHandle);   
  92. 92.                                 ProcessHandle = NULL;   
  93. 93.                             }   
  94. 94.                         }   
  95. 95.                     }   
  96. 96.                 }   
  97. 97.             }   
  98. 98.             else   
  99. 99.             {   
  100. 100.                 if(str1.Left(ProcessName.GetLength()).CompareNoCase(ProcessName) == 0)//***.exe就是你要结束的进程的名称    
  101. 101.                 {   
  102. 102.                     if (!b_kill)   
  103. 103.                     {   
  104. 104.                         b_find = true;   
  105. 105.                         goto Skip1;   
  106. 106.                     }   
  107. 107.                     else   
  108. 108.                     {   
  109. 109.                         HANDLE ProcessHandle;   
  110. 110.                         ProcessHandle = OpenProcess (PROCESS_ALL_ACCESS, FALSE, ProcessID[m_nProcess]);   
  111. 111.                         TerminateProcess(ProcessHandle, 0);   
  112. 112.                         if (ProcessHandle)   
  113. 113.                         {   
  114. 114.                             CloseHandle(ProcessHandle);   
  115. 115.                             ProcessHandle = NULL;   
  116. 116.                         }   
  117. 117.                     }   
  118. 118.                 }   
  119. 119.             }   
  120. 120.             Status=Process32Next(SnapShot,&ProcessInfo);   
  121. 121.             m_nProcess++;   
  122. 122.         }   
  123. 123.     }   
  124. 124.     catch (...) {   
  125. 125.     }   
  126. 126. Skip1:   
  127. 127.     if (SnapShot)   
  128. 128.     {   
  129. 129.         CloseHandle(SnapShot);   
  130. 130.         SnapShot = NULL;   
  131. 131.     }   
  132. 132.     if (b_find)   
  133. 133.         return TRUE;   
  134. 134.     else   
  135. 135.         return FALSE;   
  136. 136. }