怎么用VB6.0结束进程

怎么用VB6.0结束进程,第1张

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 tPEdwSize = Len(tPE) lNextProcess = Process32First(lSnapShot, tPE) Do While lNextProcess If LCase$(sProcess) = LCase$(Left(tPEszExeFile, InStr(1, tPEszExeFile, Chr(0)) - 1)) Then Dim lProcess As Long Dim lExitCode As Long lProcess = OpenProcess(1, False, tPEth32ProcessID) TerminateProcess lProcess, lExitCode CloseHandle lProcess End If lNextProcess = Process32Next(lSnapShot, tPE) Loop CloseHandle (lSnapShot) End If End Sub Private Sub command1_click() Call KillProcess("1exe") '结束"1exe"进程 , Call KillProcess("2exe") '结束"2exe"进程 , End Sub

Private Sub UserForm_Terminate()

Unload frmSub '退出当前窗体前先关闭子窗体

End Sub

扩展资料

在次代码运行的过程中,我们按Esc或者<Ctrl+Break>组合键是没有效果的。如果我们在开发好的程序时候,可以加上这句代码即可完成。顺带说下这格语句的使用方法:

Application对象的EnableCancelKey属性控制将用户中断用于运行程序的处理,语法如下:expressionEnableCancelKey,参数是expression必需的,Application对象。

有两种办法。

第一个是把启动窗体隐藏,而不是关闭。

第二种是不使用窗体启动,而是用如Sub Main这样来启动。

还有个小办法,就是弄个线程,不让它结束(比如死循环),这样即使主窗体关闭了,程序也不会退出。

以上就是关于怎么用VB6.0结束进程全部的内容,包括:怎么用VB6.0结束进程、vb中,单击按钮,结束程序执行的代码是什么、vb 如何退出所有的运行程序,但不退出界面等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/10109419.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存