如何用VB实现让程序在关闭后自动运行

我的杀毒软件老是被恶意关闭,过段时间就自己关了我想请教VB高手能否写段小程序在知道软件路径的情况下检测软件是否被关闭如果关闭则自动再次运行... 我的杀毒软件老是被恶意关闭,过段时间就自己关了 我想请教VB高手 能否写段小程序 在知道软件路径的情况下 检测软件是否被关闭 如果关闭 则自动再次运行 展开
 我来答
务元旋8d
2007-07-15 · 超过23用户采纳过TA的回答
知道答主
回答量:60
采纳率:0%
帮助的人:0
展开全部
'API声明:
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 = &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
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 Function fun_FindProcess(ByVal ProcessName As String) As Long
Dim strdata As String
Dim my As PROCESSENTRY32
Dim l As Long
Dim l1 As Long
Dim mName As String
Dim i As Integer, pid As Long
l = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0)
If l Then
my.dwSize = 1060
If (Process32First(l, my)) Then
Do
i = InStr(1, my.szExeFile, Chr(0))
mName = LCase(Left(my.szExeFile, i - 1))
If mName = LCase(ProcessName) Then
pid = my.th32ProcessID
fun_FindProcess = pid
Exit Function
End If
Loop Until (Process32Next(l, my) < 1)
End If
l1 = CloseHandle(l)
End If
fun_FindProcess = 0
End Function
'运行程序的子程序
Private Sub runexe(Byval exename as String)
Call Shell("rundll32.exe url.dll,FileProtocolHandler " & exename, vbHide)
End Sub

'窗体内部代码
’需要加入一个Timer控件,Interval属性设置为每多少毫秒检测一次。
Private Sub Timer1_Timer()
if fun_FindProcess("你要查找软件的进程名,例如avp.exe")=0 then
runexe "要运行程序的路径,例如C:\1.exe"
end if

要使用该程序必须让这个VB程序一直运行,Timer的Interval属性值太低会大量消耗内存。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式