江户川乱折腾
'VB 终止指定进程Private Type PROCESSENTRY32dwSize As LongcntUsage As Longth32ProcessID As Longth32DefaultHeapID As Longth32ModuleID As LongcntThreads As Longth32ParentProcessID As LongpcPriClassBase As LongdwFlags As LongszExeFile As String * 1024End TypePrivate Type MODULEENTRY32dwSize As Longth32ModuleID As Longth32ProcessID As LongGlblcntUsage As LongProccntUsage As LongmodBaseAddr As BytemodBaseSize As LonghModule As LongszModule As String * 256szExePath As String * 1024End TypeConst TH32CS_SNAPHEAPLIST = &H1Const TH32CS_SNAPPROCESS = &H2Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal dwFlags As Long, ByVal th32ProcessID As Long) As LongPrivate Declare Function Process32First Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As LongPrivate Declare Function Process32Next Lib "kernel32" (ByVal hSnapshot As Long, lppe As PROCESSENTRY32) As LongPrivate Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As LongPrivate Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As LongPrivate Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As LongSub KillExe(EXEName As String)Dim my As PROCESSENTRY32Dim hProcessHandle As LongDim success As LongDim l As Longl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)If l Thenmy.dwSize = 1060If (Process32First(l, my)) ThenDoIf UCase$(Right$(Left$(my.szExeFile, InStr(1, my.szExeFile, Chr$(0)) - 1), Len(EXEName))) = UCase$(EXEName) ThenhProcessHandle = OpenProcess(&H1F0FFF, True, my.th32ProcessID)If hProcessHandle <> 0 Then success = TerminateProcess(hProcessHandle, ByVal 0&)If success = 1 Then CloseHandle (hProcessHandle)End IfLoop Until (Process32Next(l, my) < 1)End IfCloseHandle lEnd IfEnd SubPrivate Sub Command1_Click()Dim a As Stringa = "c:\windows\notepad.exe" '以记事本为例KillExe aEnd Sub可以是完整文件名 比如 "c:\windows\notepad.exe"也可以不完整 比如 "notepad.exe"不区分大小写