VB高手来啊! 制作杀毒软件监测
[ 如果有满意答案,追加 100 分,信誉,不加分骂我 QQ:47492249 欢迎加Q讲解 ] 我想用 VB 编写 个程序,用来 监测 杀毒软件 的 开启(我家安装的 杀毒软件 ,常常有朋友把它关掉,系统都做了 N 次了),当杀毒软件 关闭时 自动 注销 或 重启,还有360,当360 关闭时,自动启动 "C:\safe360.exe\" 请各位大侠帮忙 在 关键 地方 要有 注释.... ````.... 还要在打开时显示在任务栏里,时刻监测,我家用的是 诺盾[进程名:egui.exe](ESET NOD32) 和 奇虎360[进程名:360tray.exe]
万分感谢,,,,,
追问:``````晕`
我问你了,怎么没提交上去```
答案:用一个计数器定时查询杀毒软件的状态,不是在启动状态下就shutdown -r -t 0重启电脑,代码如下:Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SERVICE_USER_DEFINED_CONTROL = &H100
Private Const SERVICE_CHANGE_CONFIG = &H2
Private Const SERVICE_QUERY_STATUS = &H4
Private Const SERVICE_ENUMERATE_DEPENDENTS = &H8
Private Const SERVICE_START = &H10
Private Const SERVICE_STOP = &H20
Private Const SERVICE_PAUSE_CONTINUE = &H40
Private Const SERVICE_INTERROGATE = &H80
Private Const SERVICE_QUERY_CONFIG = &H1
Private Const SERVICES_ACTIVE_DATABASE = "ServicesActive"
Private Const SC_MANAGER_CONNECT = &H1
Private Const SC_MANAGER_CREATE_SERVICE = &H2
Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Private Const SC_MANAGER_LOCK = &H8
Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10
Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Private Const SC_MANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SC_MANAGER_CONNECT Or SC_MANAGER_CREATE_SERVICE Or SC_MANAGER_ENUMERATE_SERVICE Or SC_MANAGER_LOCK Or SC_MANAGER_QUERY_LOCK_STATUS Or SC_MANAGER_MODIFY_BOOT_CONFIG)
Private Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type
Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function QueryServiceStatus Lib "advapi32.dll" (ByVal hService As Long, lpServiceStatus As SERVICE_STATUS) As Long
Private Declare Function OpenSCManager Lib "advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As String, ByVal dwDesiredAccess As Long) As Long
Private Const SERVICE_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SERVICE_QUERY_CONFIG Or SERVICE_CHANGE_CONFIG Or SERVICE_QUERY_STATUS Or SERVICE_ENUMERATE_DEPENDENTS Or SERVICE_START Or SERVICE_STOP Or SERVICE_PAUSE_CONTINUE Or SERVICE_INTERROGATE Or SERVICE_USER_DEFINED_CONTROL)
Sub check(SerName As String)
Dim hService, hSCManager, flag As Long
Dim sFlag As SERVICE_STATUS
hSCManager = OpenSCManager(Computer, SERVICES_ACTIVE_DATABASE, SC_MANAGER_ALL_ACCESS)
If hSCManager = 0 Then Exit Sub
hService = OpenService(hSCManager, SerName, SERVICE_ALL_ACCESS)
If hService Then Exit Sub
flag = QueryServiceStatus(hService, sFlag)
If sFlag.dwCurrentState <> 4 Then Shell "shutdown -r -t 0"
End Sub
使用定时器隔一段时间就调用 check("杀毒软件的系统服务名称") 就可以了
至于360的检测,可以使用进程枚举查找,找不到就关电脑。进程枚举网上有很多例子,我就不写出来了!
不建议这样做。 VB的实时监控进程的程序会使电脑变得很慢很慢。。。
上一个:VB数据处理高手来帮下忙
下一个:一份VB试卷,大鸟们帮帮忙。