概述
- '窗体中放一个默认的按钮
- 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 CloseHandle Lib "kernel32" (ByVal hObject As Long) 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 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 * 1024
- End Type
- Const TH32CS_SNAPHEAPLIST =
- Const TH32CS_SNAPPROCESS =
- Const TH32CS_SNAPTHREAD =
- Const TH32CS_SNAPMODULE =
- Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
- Const TH32CS_INHERIT =
- Private Sub Command1_Click()
- Dim my As PROCESSENTRY32
- Dim l As Long
- Dim l1 As Long
- Dim FileName As String * 9
- Dim mProcID As Long
- l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
- If l Then
- my.dwSize = 1060
- If (Process32First(l, my)) Then '遍历第一个进程
- Do
- FileName = my.szExeFile
- If UCase(FileName) = "EXCEL.EXE" Then '当前的进程是Excel
- mProcID = OpenProcess(1&, -1&, my.th32ProcessID)
- TerminateProcess mProcID, 0& '结束Excel进程
- Debug.Print "结束了" & FileName
- DoEvents
- End If
- Loop Until (Process32Next(l, my) < 1) '遍历所有进程直到返回值为False
- End If
- l1 = CloseHandle(l)
- End If
- End Sub
用VB结束所有Excel的进程,用VB开发Exxcel的应用时,如果出现意外退出,Excel进程会驻留,以后再调用Excel时不能正常使用,所以有时有必要将所有Excel全部结束
最后
以上就是朴素往事为你收集整理的用VB结束Excel的进程的全部内容,希望文章能够帮你解决用VB结束Excel的进程所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复