当前位置: 网学 > 编程文档 > VB > 正文

用VB编写监视指定进程的程序

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 12/10/16
下载{$ArticleTitle}原创论文样式
leinfo\ti.exe")
''Goto aa
End If
Label2 = sFileName

sKey = "Once"
appValue = GetSetting(AppName, Section, sKey, "0")’判断该进程起的时候是系统重新启动时还是在运行过程中启动
If appValue = "1" Then
DeleteSetting AppName, Section, sKey’如果是,删除系统重启标志
TimePassed1 = GetTickCount
Do
DoEvents
EnterResult = SendEnter()
TimePassed2 = GetTickCount
If TimePassed2 - TimePassed1 > 60000 Then Exit Do’超时1分钟就退出该循环
Loop Until EnterResult <> 0
End If

sKeyNum = "TerminateNumbers"
appValue = GetSetting(AppName, Section, sKeyNum, "4")’读取注册表中被监控进程重启次数的设置信息
NumTerminate = Val(appValue)
StartNum = 0
Label4 = NumTerminate
Label6 = 0
Dim hMenu As Long, lParam As Long, MenuCount As Long, i As Long
hMenu = GetSystemMenu(hwnd, 0)’为了不能让顾客关闭监控进程,这里屏蔽了相关的系统菜单
MenuCount = GetMenuItemCount(hMenu)
For i = 0 To MenuCount - 1
RemoveMenu hMenu, i, MF_BYPOSITION
Next
DrawMenuBar hwnd
hThread = CreateThread(0, 2000, AddressOf StartMonitor, lParam, 0, ThreadID)’创建一个监控线程
End Sub

Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 2 Then PopupMenu munSet’弹出设置菜单
End Sub

Private Sub munClose_Click()
TerminateProcess GetCurrentProcess, 1’关闭自己,因为系统菜单的关闭被屏蔽了,只能在程序中自己提供方法来关闭,又因为是多线程的,不能仅仅用Unload Me 来关闭,那只是关闭了一个线程,而监控线程没有被关闭,这里直接把当前进程给关闭了,这样可同时关闭进程中所有运行的线程。
End Sub

Private Sub munPause_Click()’这是一个有Check标记的菜单,用来Pause和Resume线程的
If munPause.Checked Then
munResume.Checked = True
ResumeThread hThread
Else
munResume.Checked = False
SuspendThread hThread
End If
munPause.Checked = Not munPause.Checked
End Sub

Private Sub munResume_Click()
If munResume.Checked Then
munPause.Checked = True
SuspendThread hThread
Else
munPause.Checked = False
ResumeThread hThread
End If
munResume.Checked = Not munResume.Checked
End Sub

Private Sub munSetFile_Click()’设置要监控进程的全路径名
Dim rFileName As String
rFileName = InputBox("请输入要监控进程的全路径名:", "输入", sFileName)
If Len(Trim(rFileName)) < 4 Then Exit Sub’ 输入明显不对,就不作任何保存直接退出该过程

If Len(Dir(rFileName, vbArchive)) > 4 Then
sFileName = rFileName
SaveSetting AppName, Section, sKeyFile, sFileName’保存正确设置
Label2 = sFileName
Dim bPaused As Long
If MsgBox("重新开始监控进程吗?", vbYesNo) = vbYes Then’询问是否立刻转到监控新的进程
TerminateThread hThread, 1
CloseHandle hThread
StartNum = 0
Label6 = "0"
bPaused = IIf(munPause.Checked, CREATE_SUSPENDED, 0)
hThread = CreateThread(0, 2000, AddressOf StartMonitor, 0, bPaused, ThreadID)’如果窗口菜单上这时设置了Pause,则这时也创建一个Suspend线程,以便和菜单保持一致。
End If
End If
End Sub

Private Sub munSetTimes_Click()
Dim NumT As String
NumT = InputBox("请输入要重启进程的最大次数:", "输入", Nu
  • 上一篇资讯: VB6内置的内码转换功能
  • 下一篇资讯: 用VB和RDO访问SQL Server
  • 网学推荐

    免费论文

    原创论文

    浏览:
    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved
    湘ICP备09003080号