关闭一个进程Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Private Const PROCESS_TERMINATE = &H1Public Function TerminateProcessByHWND(ByVal hCloseWnd As Long) As Boolean
Dim hProcessID As Long
Dim hProcess As Long
Dim hThreadID As Long
On Error GoTo PROC_EXIT
If hCloseWnd = 0 Then GoTo PROC_EXIT
hThreadID = GetWindowThreadProcessId(hCloseWnd, hProcessID)
If hThreadID = 0 Then GoTo PROC_EXIT
hProcess = OpenProcess(PROCESS_TERMINATE, False, hProcessID)
If hProcess = 0 Then GoTo PROC_EXIT
If TerminateProcess(hProcess, 0&) = 0 Then GoTo PROC_EXIT
TerminateProcessByHWND = True
PROC_EXIT:
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
End If
End Function
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function TerminateThread Lib "kernel32" (ByVal hThread As Long, ByVal dwExitCode As Long) As Long
Private Const PROCESS_TERMINATE = &H1Public Function TerminateProcessByHWND(ByVal hCloseWnd As Long) As Boolean
Dim hProcessID As Long
Dim hProcess As Long
Dim hThreadID As Long
On Error GoTo PROC_EXIT
If hCloseWnd = 0 Then GoTo PROC_EXIT
hThreadID = GetWindowThreadProcessId(hCloseWnd, hProcessID)
If hThreadID = 0 Then GoTo PROC_EXIT
hProcess = OpenProcess(PROCESS_TERMINATE, False, hProcessID)
If hProcess = 0 Then GoTo PROC_EXIT
If TerminateProcess(hProcess, 0&) = 0 Then GoTo PROC_EXIT
TerminateProcessByHWND = True
PROC_EXIT:
If Err.Number <> 0 Then
Debug.Print Err.Description
Err.Clear
End If
End Function
解决方案 »
- 指定的字符串不符合OLE DB的规定,高手 帮帮忙啊,谢谢拉
- 关于 rollback 和 commit 的使用
- 急!!!推荐能够实现子控件排序和拖动的容器控件
- 如何通过代码让日期控件(DTPicker)下拉?
- 我想单击右键时不弹出菜单该如何做?
- 使用mailto调用outlook express发送邮件的问题
- 300分,寻中文TTS完全解决方案,完美的话,可以双倍加分!!!!
- Visual Basic 6.0中怎么定义和使用类?只能新建一个Class Module才能定义吗?
- Toolboxs与imagelist问题,火急!!
- 都说vb不好用,但看看csdn的首页->最新文档其中大部分都是关于vb的hahaha
- 关于远程修改注册表
- 如何不让程序重复运行?并且让程序以最大化或者变为前台作为重复运行的响应?
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=45095
http://expert.csdn.net/Expert/FAQ/FAQ_Index.asp?id=35579
用TerminateProcessByHWND