End Process from Task Manager using VB 6 Code

后端 未结 8 1261
被撕碎了的回忆
被撕碎了的回忆 2021-01-13 03:14

I need to kill an application roughly so I can get phantom subscriber of that application in my database (this can not be produced by closing the application). Manually, if

8条回答
  •  情话喂你
    2021-01-13 03:24

    Doing this through VB6 Internal ways ...

    Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
    Public Sub KillProcess(ByVal processName As String)
           Set oWMI = GetObject("winmgmts:")
           Set oServices = oWMI.InstancesOf("win32_process")
           For Each oService In oServices
               servicename = LCase(Trim(CStr(oService.Name) & ""))
               If InStr(1, servicename, LCase(processName), vbTextCompare) > 0 Then
                  oService.Terminate
               End If
           Next
    End Sub
    

    ...and just use it as follow:

    killProcess("notepad.exe")
    

    Second option: [ by SHELL external ways... ]

    Shell "taskkill.exe /f /t /im notepad.exe"
    

提交回复
热议问题