VB 如何结束某个应用程序???

 我来答
lqq8716
2008-07-14 · 超过23用户采纳过TA的回答
知道答主
回答量:104
采纳率:0%
帮助的人:40.9万
展开全部
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 Form_Load()
Call KillProcess("notepad.exe")
Call KillProcess("notepad2.exe") '记事本做演示
End Sub
百度网友fa7f824
2008-07-14
知道答主
回答量:48
采纳率:0%
帮助的人:12.9万
展开全部
用 api 函数未免也太长了吧~
用 call shell cmd 吧~~
在窗体上建一个text1 (用来存放想要结束的程序名)
dim taskkill1 as string

taskkill1 ="cmd /c taskkill /s /im " & text1.text &" /F
call shell taskkill ,1
大概就是这样,因为我现在没用vb没有调试
可以用 cmd 看一下 taskkill 的介绍
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
谈悔来0H
2008-07-14 · TA获得超过585个赞
知道小有建树答主
回答量:361
采纳率:66%
帮助的人:118万
展开全部
unload me
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式