⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mdlprocess2.bas

📁 支持监控包括传输控制协议和 UDP 的所有的互联网传输协议。同时程序具有实时文件防修改监控功能
💻 BAS
字号:
Attribute VB_Name = "mdlProcess2"
'****************************************************************************
'人人为我,我为人人
'枕善居汉化收藏整理
'发布日期:2007/09/20
'描    述:界面清爽VB版高级专业防火墙 Ver 2.0.3
'网    站:http://www.Mndsoft.com/  (VB6源码博客)
'网    站:http://www.VbDnet.com/   (VB.NET源码博客,主要基于.NET2005)
'e-mail  :Mndsoft@163.com
'e-mail  :Mndsoft@126.com
'OICQ    :88382850
'          如果您有新的好的代码别忘记给枕善居哦!
'****************************************************************************

' #####################################################################################
' #####################################################################################
' Description:      Wraps the Windows API Functions necessary to retrieve the Process
'                     information from windows.
'
'   Needs:          PSAPI.dll to be installed and registered in the System Directory.
'
'
' #####################################################################################
' #####################################################################################
Option Explicit
'***************************************************************************************
'   API Declares
'***************************************************************************************
'Public Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long,
'Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long,
'Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal Handle As Long) As Long
'***************************************************************************************
'   Types Used to Retrieve Information From Windows
'***************************************************************************************
Public Type OSVERSIONINFO
    dwOSVersionInfoSize                             As Long
    dwMajorVersion                                  As Long
    dwMinorVersion                                  As Long
    dwBuildNumber                                   As Long
    dwPlatformId                                    As Long
    szCSDVersion                                    As String * 128
End Type
'***************************************************************************************
'   Constants to set buffer sizes, rights, and determine OS Version
'***************************************************************************************
Public Const PROCESS_QUERY_INFORMATION          As Long = 1024
Public Const PROCESS_VM_READ                    As Long = 16
Public Const MAX_PATH                           As Long = 260
'STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF
Public Const STANDARD_RIGHTS_REQUIRED           As Long = &HF0000
Public Const SYNCHRONIZE                        As Long = &H100000
Public Const PROCESS_ALL_ACCESS                 As Long = &H1F0FFF
Public Const TH32CS_SNAPPROCESS                 As Long = &H2
''Private Const TH32CS_SNAPheaplist               As Long = &H1
Public Const TH32CS_SNAPthread                  As Long = &H4
''Private Const TH32CS_SNAPmodule                 As Long = &H8
'define PROCESSENTRY32 structure
Public Type PROCESSENTRY32
    dwSize                                          As Long
    cntUsage                                        As Long
    th32ProcessID                                   As Long
    th32DefaultHeapID                               As Long
    th32ModuleID                                    As Long
    cntThreads                                      As Long
    th32ParentProcessID                             As Long
    pcPriClassBase                                  As Long
    dwFlags                                         As Long
    szExeFile                                       As String * MAX_PATH
End Type
'Used to Get the Error Message
Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER     As Long = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM         As Long = &H1000
Private Const LANG_NEUTRAL                      As Long = &H0
'Used to determine what OS Version
Public Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, _
                                                       lppe As PROCESSENTRY32) As Long
Public Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, _
                                                      lppe As PROCESSENTRY32) As Long
Public Declare Function CloseHandle Lib "kernel32.dll" (ByVal Handle As Long) As Long
Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long, _
                                                        ByVal bInheritHandle As Long, _
                                                        ByVal dwProcId As Long) As Long
Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, _
                                                                 ByVal th32ProcessID As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, _
                                                         ByVal uExitCode As Long) As Long
Private Declare Function GetLastError Lib "kernel32" () As Long
Public Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, _
                                                                             lpSource As Any, _
                                                                             ByVal dwMessageId As Long, _
                                                                             ByVal dwLanguageId As Long, _
                                                                             ByVal lpBuffer As String, _
                                                                             ByVal nSize As Long, _
                                                                             Arguments As Long) As Long
Public Sub KillProcessById(p_lngProcessId As Long)
Dim lnghProcess As Long
Dim lngReturn   As Long
'Public Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccessas As Long,
'Private Declare Function EnumProcesses Lib "psapi.dll" (ByRef lpidProcess As Long,
'Private Declare Function GetModuleFileNameExA Lib "psapi.dll" (ByVal hProcess As Long,
'Private Declare Function EnumProcessModules Lib "psapi.dll" (ByVal hProcess As Long,
'Public Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long,
'Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
'Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long,
'Private Declare Function GetLastError Lib "kernel32" () As Long
'Public Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long,
'***************************************************************************************
'   Sub Name:       KillProcessByID
'
'   Description:    Given a ProcessID, this function will get its Windows Handle and
'                       Terminate the process.
'
'   Inputs:         p_lngProcessId -->  The processid of the process to terminate.
'   Returns:        NONE
'
'***************************************************************************************
    lnghProcess = OpenProcess(1&, -1&, p_lngProcessId)
    lngReturn = TerminateProcess(lnghProcess, 0&)
    If lngReturn = 0 Then
        RetrieveError
    End If
End Sub
Private Sub RetrieveError()
Dim strBuffer As String
'***************************************************************************************
'   Sub Name:       RetrieveError
'
'   Description:    Called when the process can't terminate.  Used to retrieve the error
'                     generated during the terminate attempt.
'
'   Inputs:         NONE
'   Returns:        NONE
'
'***************************************************************************************
'Create a string buffer
    strBuffer = Space$(200)
'Format the message string
    FormatMessage FORMAT_MESSAGE_FROM_SYSTEM, ByVal 0&, GetLastError, LANG_NEUTRAL, strBuffer, 200, ByVal 0&
'Show the message
'MsgBox strBuffer
End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -