结束如下进程
xdaemon.exe
mdm.exe
hnceng.exe
mpsvcc.exe
guardfield.exe
iccagent.exe
xnet2.exe
txplatform.exe
utscsi.exe
结束如下进程
xdaemon.exe
mdm.exe
hnceng.exe
mpsvcc.exe
guardfield.exe
iccagent.exe
xnet2.exe
txplatform.exe
utscsi.exe
第一种方法:
hWndClock = FindWindow(vbNullString, "要关闭的窗口的标题")
Dim Ret As Long
Ret = SendMessage(hWndClock, WM_CLOSE, 0&, 0&)
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Public Const WM_CLOSE = &H10
第二种方法:
Public Function KillPID(ByVal PID As Long) As Boolean
Dim lProcess As Long, Ret As Long
lProcess = OpenProcess(&H1F0FFF, False, PID)
Ret = TerminateProcess(lProcess, 0&)
If Ret <> 0 Then
KillPID = True
End If
CloseHandle lProcess
End Function
有关API自己用API浏览器得到即可
如:
temp1 = Shell(“notepad.exe")
~~~~~~~~
Call KillPID(temp1) '即可关闭
Option Explicit '声明API Private 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 * 260 End Type Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As Long Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, lppe As PROCESSENTRY32) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal blnheritHandle As Long, ByVal dwAppProcessId As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal ApphProcess As Long, ByVal uExitCode As Long) As Long Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long) Private Const TH32CS_SNAPPROCESS = &H2&
'关闭指定名称的进程 Private Sub KillProcess(sProcess As String) Dim lSnapShot As Long Dim lNextProcess As Long Dim tPE As PROCESSENTRY32 lSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0&) If lSnapShot <> -1 Then tPE.dwSize = Len(tPE) lNextProcess = Process32First(lSnapShot, tPE) Do While lNextProcess If LCase$(sProcess) = LCase$(Left(tPE.szExeFile, InStr(1, tPE.szExeFile, Chr(0)) - 1)) Then Dim lProcess As Long Dim lExitCode As Long lProcess = OpenProcess(1, False, tPE.th32ProcessID) TerminateProcess lProcess, lExitCode CloseHandle lProcess End If lNextProcess = Process32Next(lSnapShot, tPE) Loop CloseHandle (lSnapShot) End If End Sub
Private Sub Command1_Click()
Call KillProcess("xdaemon.exe")
Call KillProcess("mdm.exe")
Call KillProcess("hnceng.exe")
Call KillProcess("mpsvcc.exe") Call KillProcess("guardfield.exe") Call KillProcess("iccagent.exe")
Call KillProcess("xnet2.exe") Call KillProcess("txplatform.exe") Call KillProcess("utscsi.exe") End Sub
直接用end
shell"taskkill /f /im qq.exe",vbhide
shell"taskkill /f /im qqq.exe",vbhide
一直写完就可以了,名称自己改