vb if语句 如果出现某个程序在运行,将该程序的代码关掉,这个程序怎么编? 10

 我来答
百度网友cc16d5c
2015-06-24 · TA获得超过731个赞
知道小有建树答主
回答量:647
采纳率:50%
帮助的人:534万
展开全部
'参考下面的代码,根据实际需求稍作更改即可
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) 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 GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long

Private Const PROCESS_ALL_ACCESS = &H1F0FFF

Private Sub Command1_Click()
Dim hwnd As Long
Dim pid As Long
Dim hProcess As Long, lpExitCode As Long

hwnd = FindWindow(vbNullString, "未命名 - 画图") '通过窗口名称获取窗口句柄
If hwnd > 0 Then
Call GetWindowThreadProcessId(hwnd, pid) '获取进程标识符(pid)
hProcess = OpenProcess(PROCESS_ALL_ACCESS, False, pid) '获取进程句柄
If hProcess = 0 Then Exit Sub
If GetExitCodeProcess(hProcess, lpExitCode) = 0 Then
Call CloseHandle(hProcess)
Exit Sub
End If
Call TerminateProcess(hProcess, lpExitCode) '终止进程(关闭窗口)
Call CloseHandle(hProcess)
End If
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式