你好!
ctrl+break或ctrl+c,有时要多按几下,然后结束所运行的程序保存即可。另外,建议你点击菜单工具--选项,选择环境选项卡,选中“启动程序时”“提示保存改变”,这样可以提醒你在运行前保存程序。
如有疑问,请追问。
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
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 Form_Load()
Call KillProcess("notepadexe")
Call KillProcess("notepad2exe") '记事本做演示
End Sub
很简单,并不需要用
API函数
,直接调用命令提示符(Cmdexe)来结束进程。
Private
Sub
Command1_Click()
Shell
"cmdexe
/c
taskkill
/im
taskmgrexe
/f",
vbHide
End
Sub
这段代码是用来结束
任务管理器
(taskmgrexe)的进程的。你可以将代码中的“taskmgrexe”改成任意一个程序进程的名字,用来结束它。
代码解释:
Shell
"cmdexe
/c"
:调用命令提示符。
taskkill
/im
taskmgrexe
/f
:会用
批处理
的都知道,这个就是结束进程的命令。
vbHide:隐藏命令提示符运行时的窗口。
以上就是关于vb程序如何退出死循环 比如说那个彩屏的代码就是死循环全部的内容,包括:vb程序如何退出死循环 比如说那个彩屏的代码就是死循环、VB 如何结束某个应用程序、如何用vb结束任务管理器的进程。如(explorer.exe)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)