VBS脚本写的Windows硬件检测工具分享

论坛 期权论坛     
niminba   2021-5-22 22:21   55   0
<div class="blockcode">
<pre class="brush:vb;">
Const MyName = "Windows硬件检视工具(测试版) --by:Rex.Pack(雷克斯.派)"

If Not LCase(Replace(WScript.FullName, WScript.Path &amp; "\", "")) = "cscript.exe" Then
Set WS = CreateObject("WScript.Shell")
WS.Run "CMD /c mode con: cols=115 &amp; Color 0A &amp; Title " &amp; MyName &amp; " &amp; CScript //nologo """ &amp; WScript.ScriptFullName &amp; """"
WScript.Quit
End If
'----初始化
Set SD = CreateObject("Scripting.Dictionary")
SD.CompareMode = vbTextCompare
Set S = New BaseStr
Set PC = New BasePC
Set WMI = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
CmdArr = Split(" OS CPU Board Memory Video Disk USB CacheMemory NetWork BIOS Sound Battery PortableBattery" &amp; " S1 S2 S3 S4")
With SD
.Add "&#63;", "Call Menu"
.Add "e", "WScript.Quit"
For I = 1 To 17
  .Add CStr(I), CmdArr(I)
Next
.Add "a", "1-6"
.Add "b", "7-9"
.Add "c", "10-13"
.Add "d", "14-17"
End With

Echo MyName

Call Menu
Call Main


'----CO
Sub Menu()
Echo "[设备列表]"
Echo " 常用组 A: 1.OS 2.CPU 3.主板 4.内存 5.显卡 6.硬盘"
Echo " 次级组 B: 7.USB 8.缓存 9.网卡"
Echo " 酱油组 C: 10.BIOS 11.声卡 电池(12.内部 13.便携)"
Echo "[测试CPU]"
Echo " 测试组 D: 14.变量幂次方运算 15.字符叠合 16.加法计算 17.叠加计算"
End Sub

Sub Main()
Print "&gt;": GetNum = Trim(InPut)
With SD
  If .Exists(GetNum) Then
   If IsNumeric(GetNum) Then
    Echo Eval("PC." &amp; .Item(GetNum))
   Else
    ArrLU = Split(.Item(GetNum), "-")
    For L = ArrLU(0) To ArrLU(1)
     Echo Eval("PC." &amp; .Item(CStr(L)))
    Next
   End If
  Else
   Echo "#不支持的命令"
  End If
End With

If Not Err.Number = 0 Then Echo "&gt;X": Err.Clear
Call Main
End Sub



'DDC
Class BaseStr
Private Strs

Private Sub Class_Initialize()
  Strs = ""
End Sub

Private Sub Class_Terminate()
  Call Cls
End Sub

Public Sub Cls()
  Strs = Empty
End Sub

Public Property Let I(ByVal Str)
  If Left(Str, 1) = "☆" Then Str = Str &amp; String(80, "=")
  Strs = Strs &amp; vbCrLf &amp; Str
End Property

Public Default Property Get I()
  I = Strs
  Cls
End Property
End Class

Class BasePC
Private DPS

Private Sub Class_Initialize()
  DPS = 200
End Sub

Private Sub Class_Terminate()
  DPS = Empty
End Sub

Function S1()
  S1 = "变量幂次方运算 " &amp; DPS &amp; "万次用时:" &amp; RT("TestVar = I ^ 2", DPS * 10000)
End Function

Function S2()
  S2 = "字符叠合 " &amp; DPS &amp; "000次用时:" &amp; RT("TestVar = TestVar &amp; vbTab", DPS * 1000)
End Function

Function S3()
  S3 = "加法计算 " &amp; DPS &amp; "万次用时:" &amp; RT("TestVar = 86 + 32", DPS * 10000)
End Function

Function S4()
  S4 = "叠加计算 " &amp; DPS &amp; "万次用时:" &amp; RT("TestVar = TestVar + I", DPS * 10000)
End Function

Private Function RT(ByVal MathExp, ByVal Num)
  Dim NowTimer, NewTimer, TestVar
  NowTimer = Timer
  For I = 1 To Num
   ExeCute MathExp
  Next
  NewTimer = FormatNumber((Timer - NowTimer) * 1000, 3, True, , False) &amp; "ms"
  RT = NewTimer
  TestVar = Empty
End Function

Function BIOS()
  On Error Resume Next
  S.I = "☆[BIOS]"
  S.I = "┏━━━━━━━━━━━━━┉"
  For Each TempObj In WMI.InstancesOf("Win32_BIOS")
   With TempObj
    S.I = "┣厂商  :" &amp; .Manufacturer
    S.I = "┇日期  :" &amp; .ReleaseDate
    S.I = "┇OEM 版本 :" &amp; .Version
    S.I = "┇BIOS 版本 :" &amp; .SMBIOSBIOSVersion
    S.I = "┇Major版本 :" &amp; .SMBIOSMajorVersion
    S.I = "┇状态  :" &amp; .Status
   End With
  Next
  S.I = "┗━━━━━━━━━━━━━┉"
  BIOS = S
End Function

Function OS()
  On Error Resume Next
  S.I = "☆[操作系统]"
  S.I = "┏━━━━━━━━━━━━━┉"
  For Each TempObj in WMI.InstancesOf("Win32_OperatingSystem")
   With TempObj
    S.I = "┣标签  :" &amp; .Caption
    S.I = "┇CSDV  :" &amp; .CSDVersion
    S.I = "┇版本  :" &amp; .Version
    S.I = "┇RAM识别:" &amp; .TotalVisibleMemorySize / 1024 &amp; "MB"
    S.I = "┇RAM可用:" &amp; .FreePhysicalMemory / 1024 &amp; "MB"
   End With
  Next
  S.I = "┗━━━━━━━━━━━━━┉"
  OS = S
End Function

Function Board()
  On Error Resume Next
  S.I = "☆[主板]"
  S.I = "┏━━━━━━━━━━━━━┉"
  For Each TempObj In WMI.InstancesOf("Win32_BaseBoard")
   With TempObj
    S.I = "┣标签:" &amp; .Caption
    S.I = "┇编号:" &amp; .Product
    S.I = "┇序号:" &amp; .SerialNumber
    S.I = "┇名称:" &amp; .Name
    S.I = "┇版本:" &amp; .Version
    S.I = "┇厂商:" &amp; .Manufacturer
    S.I = "┇状态:" &amp; .Status
   End With
  Next
  S.I = "┗━━━━━━━━━━━━━┉"
  Board = S
End Function

Function CPU()
  On Error Resume Next
  S.I = "☆[CPU]"
  S.I = "┏━━━━━━━━━━━━━┉"
  For Each TempObj In WMI.InstancesOf("Win32_Processor")
   With TempObj
    MCS = .MaxClockSpeed
    CCS = .CurrentClockSpeed
    If MCS Mod 2 = 1 Then MCS = CCS + 1
    If CCS Mod 2 = 1 Then CCS = CCS + 1
    If CCS = MCS Then
     Set SRP = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
     SRP.GetDWORDValue &amp;H80000002, "HARDWARE\DESCRIPTION\System\CentralProcessor\0", "~MHz
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1060120
帖子:212021
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP