VB 结束指定命令行/PID/路径进程,VB 结束指定命令行径进程,VB 结束指定PID进程,VB 结束指定路径进程,VB 结束指定进程,VB 结束指定命令行,VB 结束指定PID,VB 结束指定路径,VB 结束进程,GetObject("winmgmts:\\.\root\cimv2:win32_process"),VB Ename.CommandLine,VB Ename.Terminate,VB Ename.ProcessID,VB Ename.executablepath。

VB 结束指定命令行/PID/路径进程:

Public Function PathKE(P As String)                                             '结束指定[命令行/PID/路径]进程
    On Error GoTo Over
    Dim Ename
    For Each Ename In GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_ '循环进程
        If Left$(P, 3) = "MLH" Then                                             '判断是根据路径结束进程还是根据命令行结束进程
            If InStr(LCase(Ename.CommandLine), LCase(Mid(P, 4))) > 0 Then Ename.Terminate '全部转换成小写比较进程命令行,然后结束
        ElseIf Left$(P, 3) = "PID" Then                                         '根据PID结束
            If CStr(Ename.ProcessID) = Mid(P, 4) Then Ename.Terminate           '全部转换成字符串比较进程PID,然后结束
        Else
            If LCase(Ename.executablepath) = LCase(P) Then Ename.Terminate      '全部转换成小写比较进程路径,然后结束
        End If
    Next
Over:
End Function

VB结束指定路径的进程:

简洁版:
Dim ename
For Each ename In GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_ '循环进程
    If LCase(ename.ExecutablePath) = LCase("CSTRIKE-ONLINE.EXE") Then ename.Terminate '全部转换成小写比较,然后结束
Next

---------------------------------------------------------------------------

啰嗦版:
Private Sub Command1_Click()
    Dim objWMIService As Object, colProcesslist As Object, objProcess As Object
    Set objWMIService = CreateObject("winmgmts:{impersonationLevel=Impersonate}!root\cimv2")
    Set colProcesslist = objWMIService.ExecQuery("select * from win32_process")
    For Each objProcess In colProcesslist
        If LCase(objProcess.ExecutablePath) = LCase(Environ("windir") & "\demo.exe") Then objProcess.Terminate
    Next
End Sub

VB结束制定命令行进程:

Dim ename
For Each ename In GetObject("winmgmts:\\.\root\cimv2:win32_process").instances_ '循环进程
    If InStr(LCase(ename.CommandLine), LCase("CSTRIKE-ONLINE.EXE")) > 0 Then ename.Terminate '全部转换成小写比较,然后结束
Next