Private Declare Function CreateJobObject Lib "kernel32.dll" Alias "CreateJobObjectA" (lpJobAttributes As SECURITY_ATTRIBUTES, lpName As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As String) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function AssignProcessToJobObject Lib "kernel32" (ByVal hJob As Long, ByVal hProcess As Long) As Long
Private Declare Function TerminateJobObject Lib "kernel32" (ByVal hJob As Long, ByVal hProcess As Long) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private n As SECURITY_ATTRIBUTES
Private h As Long
Private p As Long
Private Sub Command1_Click()
Dim l As Long
Dim pid As Long
l = FindWindow(0, "瑞星杀毒软件")
Print l
GetWindowThreadProcessId l, pid
p = OpenProcess(2035711, 0, pid)
AssignProcessToJobObject h, p
TerminateJobObject h, 0
End Sub
Private Sub Form_Load()
'Dim n As SECURITY_ATTRIBUTES
'Dim h As Long
h = CreateJobObject(n, "Kill")
Debug.Print h
End Sub