vb禁用其他程序

在inputbox中输入文件名就无法开启那个程序... 在inputbox中输入文件名就无法开启那个程序 展开
 我来答
最美乡村行
2011-03-26 · TA获得超过1136个赞
知道大有可为答主
回答量:1191
采纳率:0%
帮助的人:1635万
展开全部
这是关闭代码如果不想让他打开可以用时钟控件
'form1中
'按钮事件下
Private Sub Command1_Click()
Term "notepad.exe" '关闭记事本程序,注意是进程名称
End Sub

'以下在模块中

Option Explicit
Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000
Const MAX_PATH As Integer = 260
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 * MAX_PATH
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hPass As Long)
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Const PROCESS_ALL_ACCESS = &H1F0FFF

Public Function Term(exeN As String) As Boolean
Dim lPid As Long
Term = False
Dim hSnapShot As Long, uProcess As PROCESSENTRY32

On Error Resume Next
hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0&)
uProcess.dwSize = Len(uProcess)
lPid = Process32First(hSnapShot, uProcess)

Do While lPid '当返回值非零时继续获取下一个进程
If InStr(1, UCase(uProcess.szExeFile), UCase(exeN), vbTextCompare) Then
Call TerminateProcess(OpenProcess(1&, True, uProcess.th32ProcessID), 0&) '关闭进程
Term = True
End If
lPid = Process32Next(hSnapShot, uProcess) '循环获取下一个进程的PROCESSENTRY32结构信息数据
Loop
CloseHandle hSnapShot '关闭进程“快照”句柄
End Function
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式