Option ExplicitPrivate Const TH32CS_SNAPPROCESS As Long = 2&
Private Const MAX_PATH As Integer = 260
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 TypePrivate Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessID As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)Public ListOfActiveProcess() As PROCESSENTRY32Public Function GetActiveProcess(Optional strFile As String) As Long  '读取活动进程
    Dim hToolhelpSnapshot As Long
    Dim tProcess As PROCESSENTRY32
    Dim R As Long, i As Integer
    hToolhelpSnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
    If hToolhelpSnapshot = 0 Then
        GetActiveProcess = 0
        Exit Function
    End If
    With tProcess
        .dwSize = Len(tProcess)
        R = ProcessFirst(hToolhelpSnapshot, tProcess)
        Do While R
            If strFile = "" Then
                i = i + 1
                ReDim Preserve ListOfActiveProcess(1 To i)
                ListOfActiveProcess(i) = tProcess
            Else
                If LCase(strFile) = LCase(fDelInvaildChr(tProcess.szExeFile)) Then
                   Call Terminate_Process(tProcess.th32ProcessID)
                   GetActiveProcess = -1
                   GoTo 1
                End If
            End If
            R = ProcessNext(hToolhelpSnapshot, tProcess)
        Loop
    End With
    GetActiveProcess = i
1:
    Call CloseHandle(hToolhelpSnapshot)
End Function'结束进程
Public Function Terminate_Process(ByVal process_ID As Long)
    Dim lProcess As Long
    Dim lReturn As Long
    lProcess = OpenProcess(&H1F0FFF, 0&, process_ID)
    lReturn = TerminateProcess(lProcess, 0&)
End Function''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'去掉固定长度字符串右边的NULL字符(ASCII值为0)和SPACE字符(ASCII值为32)函数
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function fDelInvaildChr(ByVal str As String) As String
    On Error Resume Next
    Dim i As Long
    str = Trim(str)
    For i = Len(str) To 1 Step -1
    If Asc(Mid(str, i, 1)) <> 0 And Asc(Mid(str, i, 1)) <> 32 Then
    fDelInvaildChr = Left(str, i)
    Exit For
    End If
    Next
End Function