无忧启动论坛

 找回密码
 注册
搜索
系统gho:最纯净好用系统下载站广告联系 微信:wuyouceo QQ:184822951
查看: 4141|回复: 18
打印 上一主题 下一主题

[发布] vbs实现 扫描检测硬件改动

  [复制链接]
1#
发表于 2019-9-29 10:22:28 | 显示全部楼层
本帖最后由 9zhmke 于 2019-9-29 17:55 编辑

我以前也是这么做,后来发现总是不准确。推荐个改进方法,把暂停的时间改为检测CPU占有率和硬盘使用率,如果这两个都低就可以直接点击了,如果这有一个高就多等一会儿。
这几个有些是网上抄改有些是自己写的,典型使用方法:
while CPU_busy >5 or Hard_busy >10240: wscript.sleep 200:Wend   '如果CPU忙或者硬盘忙则等待


  1. Function Ping(url) '检查网络Ping值,单位毫秒
  2.     Set objWMI = GetObject("winmgmts:\\.")
  3.     Set colPings = objWMI.ExecQuery ("Select * From Win32_PingStatus where Address = '" & url & "'")
  4.     Ping=9999
  5.     On error resume next
  6.         For Each objPing in colPings
  7.             Ping=objPing.ResponseTime+0
  8.         Next
  9.     On error goto 0
  10. End Function
复制代码

  1. Function Wait(proc) '等待程序完成,十秒还没完成则退出
  2.     dim mark,obj,proce,data,x
  3.     do
  4.       mark=0
  5.       Set obj = getobject("winmgmts:\\.\root\cimv2")
  6.       Set proce = obj.execquery("select * from win32_process")
  7.       For each x in proce
  8.         if lcase(x.name)=proc then mark=1
  9.         data=data+1
  10.       next
  11.       if mark=0 or data>100 then exit do
  12.       wscript.sleep 100
  13.       Set obj = nothing
  14.       Set proce = nothing
  15.     loop
  16. End Function
复制代码

  1. Function Hard_busy() '硬盘忙闲
  2.     Dim vName,IDE,cPPP,sNow,A,B,R1,W1,R2,W2,read,write
  3.     Set objWMIService=GetObject("winmgmts:\\.\root\cimv2")
  4.     Set IDE = objWMIService.ExecQuery("Select * from Win32_DiskDrive WHERE InterfaceType='IDE'")
  5.     Set cPPP = objWMIService.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk WHERE Name<>'_Total'")
  6.     DskPs=WshShell.ExpandEnvironmentStrings("%SystemDrive%") '取系统驱动器
  7.         Set A = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk Where Name = '"& DskPs &"'")
  8.         For Each B In A
  9.             R1 = B.DiskReadBytesPersec: W1 = B.DiskWriteBytesPersec
  10.             If RA0 = "" Then RA0 = B.DiskReadBytesPersec Else RA1 = R1 End If
  11.             If WA0 = "" Then WA0 = B.DiskWriteBytesPersec Else WA1 = W1 End If
  12.         Next
  13.     Set A = Nothing
  14.     WScript.Sleep(500)
  15.     Set A = objWMIService.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk Where Name = '"& DskPs &"'")
  16.     For Each B In A
  17.         R2 = B.DiskReadBytesPersec
  18.         W2 = B.DiskWriteBytesPersec
  19.     Next
  20.     Set A = Nothing
  21.     read=R2-R1:write=W2-W1   'msgbox  "半秒实时读取:" & read & "/s 实时写人:" & write
  22.     Hard_busy = read + write
  23.     Set IDE=nothing
  24.     Set cPPP=nothing
  25. End Function
复制代码

  1. Function CPU_busy() 'CPU使用率
  2.     dim objProc
  3.     Set objProc = GetObject("winmgmts:\\.\root\cimv2:win32_processor='cpu0'")
  4.     CPU_busy=objProc.LoadPercentage 'CPU使用率
  5.     Set objProc = nothing
  6. End Function
复制代码

点评

嗯,谢谢,我那个的确不怎么准确,凑合,主要自用,顺便给人提供点思路  详情 回复 发表于 2019-9-29 14:55
神奇的vbs  发表于 2019-9-29 10:48
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|捐助支持|无忧启动 ( 闽ICP备05002490号-1 )

闽公网安备 35020302032614号

GMT+8, 2024-5-2 10:38

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表