
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("1.exe") '
结束"1.exe"进程笑闭察 , Call KillProcess("2.exe") '结束"2.exe"进程 , End Sub
可以参考下面的两种参考方法旅岩升:
第一种:用cmd中的taskkill结束程序
shell ”cmd/c taskkill /f /im 你的进程名.exe“
第二种:(WIN7)以下的电脑可以使用,用ntsd结束程序枣亩
shell ”cmd/c ntsd -c q -pn 用户的进程名.exe“
扩展资料:
参考语句
For Each...Next 语句: 对于数组或集合中的每一个元素,重复一组语句。
FormatDateTime 函数: 返回格式化为日期或时间的表达式。
FormatNumber 函数: 返回格式化为数的表达式。
Function 语句: 声明形成 Function 过程体的名称、参数拆老和代码。
GetObject 函数: 从文件返回对“自动”对象的访问。
参考资料来源:百度百科-Visual Basic
评论列表(0条)