| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1682 人关注过本帖
标题:[求助] 求在程序运行时禁止系统进程打开的方法
只看楼主 加入收藏
huangjiehong
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-4-16
收藏
 问题点数:0 回复次数:9 
[求助] 求在程序运行时禁止系统进程打开的方法

本人学习VB不足两月,想要在编程中禁止某个系统进程打开,请问有什么方法。我找到一个用VBS脚本来实现的方法,就是不懂在VB编程中实现。VBS脚本代码附上
dim qobj,pipe,good
do
set qobj=getobject("winmgmts:\\"&good$"\root\cimv2")
set pipe=qobj.execquery("select*from win32-process where name='QQ.exe")
for each i in pipe
i.terminate()
next
wscript.sleep 1
loop
先谢谢各位啦

搜索更多相关主题的帖子: 系统进程 pipe qobj VBS 
2006-04-26 14:56
huangjiehong
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-4-16
收藏
得分:0 

各位大侠,回复一下嘛。感激不尽啊

2006-05-07 19:08
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

运行vb6.0,新建一个标准exe工程,在窗体里添加一个计时器控件.
然后编写如下代码.可以禁止计算器运行..
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Const WM_CLOSE = &H10

Private Sub Form_Load()
Timer1.Enabled = True
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim FindCalc As Long
FindCalc = FindWindow(vbNullString, "计算器")
If FindCalc <> 0 Then
MsgBox "不可以运行计算器"
Call PostMessage(FindCalc, WM_CLOSE, 0, 0)
End If
End Sub


我的msn: myfend@
2006-05-07 19:30
huangjiehong
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-4-16
收藏
得分:0 

多谢指点,可是我看不懂在哪里指定禁止计算器运行的。可不可以指定禁止任何我想要禁止的呢

2006-05-08 10:54
风沙雪雨
Rank: 1
等 级:新手上路
帖 子:43
专家分:0
注 册:2006-5-4
收藏
得分:0 

Private Sub Timer1_Timer()
Dim FindCalc As Long
FindCalc = FindWindow(vbNullString, "计算器")
找到你想要找的进程名.(ID)
If FindCalc <> 0 Then
MsgBox "不可以运行计算器"
Call PostMessage(FindCalc, WM_CLOSE, 0, 0)
给这个进程发送关闭信号.一般下可以关闭大多数进程.
End If
End Sub

2006-05-08 12:34
huangjiehong
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-4-16
收藏
得分:0 

还是不明白,请问哪个是程序要关闭的进程名呢??

2006-05-08 19:00
purana
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:广东-广州
等 级:版主
威 望:66
帖 子:6039
专家分:0
注 册:2005-6-17
收藏
得分:0 

你想关闭某个进程是吧..发个代码你看看
此代码调用下面程序...
'查找进程
if FindProcess("qq.exe")=true then
msgbox "QQ进程存在!"
end if
'结束进程
CloseProcess "qq.exe"

''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit

Public Declare Function ProcessFirst Lib "kernel32" Alias "Process32First" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function ProcessNext Lib "kernel32" Alias "Process32Next" (ByVal hSnapshot As Long, uProcess As PROCESSENTRY32) As Long
Public Declare Function CreateToolhelpSnapshot Lib "kernel32" Alias "CreateToolhelp32Snapshot" (ByVal lFlags As Long, lProcessID As Long) As Long
Public Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Public Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long

Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const PROCESS_TERMINATE = 1

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 Type MyProcess
ExeName As String
Pid As Long
End Type

Public Function CloseProcess(ByVal ProName As String) As Integer
Dim tPID As Long
Dim tPHwnd As Long

If FindProcess(ProName, tPID) = False Then
Exit Function
Else
tPHwnd = OpenProcess(PROCESS_TERMINATE, False, tPID)
Debug.Print tPHwnd
If tPHwnd Then
CloseProcess = TerminateProcess(tPHwnd, 0)
End If
End If
End Function

Public Function FindProcess(ByVal ProName As String, Optional ByRef Pid As Long) As Boolean
Dim MyProcess As PROCESSENTRY32
Dim mySnapshot As Long
Dim ProData() As MyProcess

ReDim ProData(0)

MyProcess.dwSize = Len(MyProcess)
mySnapshot = CreateToolhelpSnapshot(TH32CS_SNAPPROCESS, 0&)
ProcessFirst mySnapshot, MyProcess

ReDim Preserve ProData(UBound(ProData) + 1)

ProData(UBound(ProData)).ExeName = Left(MyProcess.szexeFile, InStr(MyProcess.szexeFile, Chr(0)) - 1)
ProData(UBound(ProData)).Pid = MyProcess.th32ProcessID

'Debug.Print ProData(UBound(ProData)).ExeName

If LCase(ProData(UBound(ProData)).ExeName) = LCase(ProName) Then
FindProcess = True
Pid = ProData(UBound(ProData)).Pid
Exit Function
End If

MyProcess.szexeFile = ""

While ProcessNext(mySnapshot, MyProcess)
ReDim Preserve ProData(UBound(ProData) + 1)

ProData(UBound(ProData)).ExeName = Left(MyProcess.szexeFile, InStr(MyProcess.szexeFile, Chr(0)) - 1)
ProData(UBound(ProData)).Pid = MyProcess.th32ProcessID

' Debug.Print ProData(UBound(ProData)).ExeName

If LCase(ProData(UBound(ProData)).ExeName) = LCase(ProName) Then
FindProcess = True
Pid = ProData(UBound(ProData)).Pid
Exit Function
End If

MyProcess.szexeFile = ""
Wend

End Function


我的msn: myfend@
2006-05-08 19:29
huangjiehong
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-4-16
收藏
得分:0 

不是啊,我是想禁止某个进程。 不给它打开 请问有什么简单易懂的方法吗?

2006-05-09 10:02
freeforever
Rank: 4
等 级:业余侠客
威 望:3
帖 子:368
专家分:201
注 册:2005-11-2
收藏
得分:0 
就是7楼的方法,用SendMessage或PostMessage都有关不掉的时候,尤其是系统进程

Dim lngPID As Long '窗口的进程标识
Dim hnd As Long '进程退出的标识
Dim lExitCode As Long '进程退出"代码"
hnd = OpenProcess(PROCESS_TERMINATE, 0, lngPID)
GetExitCodeProcess hnd, lExitCode
TerminateProcess hnd, lExitCode
CloseHandle hnd '将退出标识归还系统

进程标识由GetWindowThreadProcessId函数得到,这个函数要用的窗口句柄用FindWindow得到

其实我也很无聊!
2006-05-09 11:38
huangjiehong
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-4-16
收藏
得分:0 

可是我要禁止的进程名放在什么位置啊
还有7楼的这段代码粘贴进VB里就显示出错

Public Const FORMAT_MESSAGE_ALLOCATE_BUFFER = &H100
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000
Public Const TH32CS_SNAPPROCESS As Long = 2&
Public Const PROCESS_TERMINATE = 1
是怎么回事啊

2006-05-09 13:57
快速回复:[求助] 求在程序运行时禁止系统进程打开的方法
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.029422 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved