VBS脚本写的Windows硬件检测工具分享
程序员文章站
2024-01-02 16:30:46
const myname = "windows硬件检视工具(测试版) --by:rex.pack(雷克斯.派)"
if not lcase(replace(w...
const myname = "windows硬件检视工具(测试版) --by:rex.pack(雷克斯.派)" if not lcase(replace(wscript.fullname, wscript.path & "\", "")) = "cscript.exe" then set ws = createobject("wscript.shell") ws.run "cmd /c mode con: cols=115 & color 0a & title " & myname & " & cscript //nologo """ & wscript.scriptfullname & """" 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" & " s1 s2 s3 s4") with sd .add "?", "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 ">": getnum = trim(input) with sd if .exists(getnum) then if isnumeric(getnum) then echo eval("pc." & .item(getnum)) else arrlu = split(.item(getnum), "-") for l = arrlu(0) to arrlu(1) echo eval("pc." & .item(cstr(l))) next end if else echo "#不支持的命令" end if end with if not err.number = 0 then echo ">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 & string(80, "=") strs = strs & vbcrlf & 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 = "变量幂次方运算 " & dps & "万次用时:" & rt("testvar = i ^ 2", dps * 10000) end function function s2() s2 = "字符叠合 " & dps & "000次用时:" & rt("testvar = testvar & vbtab", dps * 1000) end function function s3() s3 = "加法计算 " & dps & "万次用时:" & rt("testvar = 86 + 32", dps * 10000) end function function s4() s4 = "叠加计算 " & dps & "万次用时:" & 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) & "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 = "┣厂商 :" & .manufacturer s.i = "┇日期 :" & .releasedate s.i = "┇oem 版本 :" & .version s.i = "┇bios 版本 :" & .smbiosbiosversion s.i = "┇major版本 :" & .smbiosmajorversion s.i = "┇状态 :" & .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 = "┣标签 :" & .caption s.i = "┇csdv :" & .csdversion s.i = "┇版本 :" & .version s.i = "┇ram识别:" & .totalvisiblememorysize / 1024 & "mb" s.i = "┇ram可用:" & .freephysicalmemory / 1024 & "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 = "┣标签:" & .caption s.i = "┇编号:" & .product s.i = "┇序号:" & .serialnumber s.i = "┇名称:" & .name s.i = "┇版本:" & .version s.i = "┇厂商:" & .manufacturer s.i = "┇状态:" & .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 &h80000002, "hardware\description\system\centralprocessor\0", "~mhz", oc set srp = nothing else oc = ccs end if if oc mod 2 = 1 then oc = oc + 1 fc = oc - mcs if fc > +10 then oclc = "超" if fc < -10 then oclc = "降" oclc = oclc & "频比率:" & formatpercent(fc / mcs, true, true) s.i = "┣cpu 名称:" & trim(.name) s.i = "┇cpu 架构:" & .description s.i = "┇制造厂商:" & .manufacturer s.i = "┇插口规格:" & .socketdesignation s.i = "┇cpu 数量:" & .cpustatus & " " & string(.cpustatus, "※") s.i = "┇核心数量:" & .numberofcores & " " & string(.numberofcores, "∷") s.i = "┇线程数量:" & .numberoflogicalprocessors & " " & string(.numberoflogicalprocessors, "≈") s.i = "┇地址位宽:" & .addresswidth & " bit" s.i = "┇数据位宽:" & .datawidth & " bit" s.i = "┇cpu 电压:" & .currentvoltage / 10 & "v" s.i = "┇外部频率:" & .extclock & " mhz" s.i = "┇当前频率:" & oc & " mhz, " & oclc s.i = "┇原始频率:" & mcs & " mhz" s.i = "┇cpu占用%:" & .loadpercentage & "%" end with next s.i = "┗━━━━━━━━━━━━━┉" cpu = s end function function cachememory() on error resume next s.i = "☆[缓存内存]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_cachememory") with tempobj if .maxcachesize > 0 then select case .purpose case "l1 cache" addstr = "(+databit)" case else end select s.i = "┇作用位:" & .purpose & " id:" & .deviceid & ":" & .maxcachesize & "kb" & addstr addstr = "" end if end with next s.i = "┗━━━━━━━━━━━━━┉" cachememory = s end function function memory() on error resume next temparr = split("unknown other dram synchronous-dram cache-dram edo edram vram sram ram rom flash eeprom feprom eprom cdram 3dram sdram sgram rdram ddr ddr-2") s.i = "☆[内存]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_physicalmemory") with tempobj s.i = "┣名称/标签:" & .name & "/" & .caption s.i = "┇bl :" & .banklabel s.i = "┇槽 :" & .devicelocator s.i = "┇容量 :" & .capacity / 1048576 & "mb" s.i = "┇类型 :" & temparr(.memorytype) s.i = "┇速率 :" & .speed & "mhz" s.i = "┇制造商 :" & .manufacturer s.i = "┇热插拔 :" & iif(.hotswappable = true, true, false) s.i = "┇总位宽 :" & .totalwidth s.i = "┇数据位宽 :" & .datawidth s.i = "┇部分序号 :" & .partnumber end with next s.i = "┗━━━━━━━━━━━━━┉" memory = s end function function video() on error resume next temparr1 = split(" 其他 未知 cga ega vga svga mda hgc mcga 8514a xga linear frame buffer" & space(160 - 14) & "pc-98") temparr2 = split(" 其他 未知 隔行 逐行") s.i = "☆[显卡]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_videocontroller") with tempobj s.i = "┣接口 :" & temparr1(.videoarchitecture) s.i = "┇名称 :" & .name s.i = "┇标签 :" & .caption s.i = "┇id :" & .deviceid s.i = "┇gpu :" & .videoprocessor s.i = "┇制造商 :" & .adaptercompatibility s.i = "┇物理显存 :" & .adapterram / 1048576 & "mb" s.i = "┇扫描模式 :" & iif(.currentscanmode = false, false, temparr2(.currentscanmode)) s.i = "┇分辨率 :" & .currenthorizontalresolution & " x " & .currentverticalresolution s.i = "┇色位盘 :" & .currentbitsperpixel & "bit" s.i = "┇刷新率 :" & .currentrefreshrate & "hz" & "(" & .minrefreshrate & "-" & .maxrefreshrate& ")" s.i = "┇驱动版本 :" & .driverversion end with next s.i = "┗━━━━━━━━━━━━━┉" video = s end function function disk() on error resume next s.i = "☆[硬盘]" for each tempobj in wmi.instancesof("win32_diskdrive") with tempobj s.i = "┏[磁盘:" & .index & "]━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┉" s.i = "┇名称 :" & .name s.i = "┇标签 :" & .caption s.i = "┇接口 :" & .interfacetype s.i = "┇制造商 :" & .manufacturer s.i = "┇序号 :" & .serialnumber s.i = "┇介质描述:" & .description & " " & "┇介质类型:" & .mediatype s.i = "┇柱面数 :" & .totalcylinders & " " & "┇磁头数 :" & .totalheads s.i = "┇标准容量:" & formatnumber(.size / 1000000000, 2, true) & "gb" & " " & "┇实际容量:" & formatnumber(.size / 1073741824, 2, true) & "gb" s.i = "┇分区数量:" & .partitions s.i = "┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┉" s.i = "┣[分区]┳━━━┳━━━━━━━┳━━━━━━━━━━━┳━━━━━┉" s.i = "┇ 索引 ┇主分区┇容量(gb) ┇块(大小x数量) ┇属性" s.i = "┣━━━╋━━━╋━━━━━━━╋━━━━━━━━━━━╋━━━━━┉" for each tempobj0 in wmi.instancesof("win32_diskpartition") if .index = tempobj0.diskindex then s.i = "┇ " & tempobj0.index & _ " ┇" & tempobj0.primarypartition & _ " ┇" & formatnumber(tempobj0.size / 1073741824, 2, true) & "gb" & _ " ┇" & tempobj0.blocksize & "x" & tempobj0.numberofblocks & _ " ┇" & _ tif(tempobj0.bootpartition, "引导,") & _ tif(tempobj0.hiddensectors, "隐藏,") & _ tif(tempobj0.bootable, "启动.") end if next s.i = "┣━━━┻━━━┻━━━━━━━┻━━━━━━━━━━━┻━━━━━┉" s.i = "┣[扇区]━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┉" s.i = "┇磁道扇区:" & .sectorspertrack s.i = "┇扇区大小:" & .bytespersector s.i = "┇总扇区数:" & .totalsectors s.i = "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┉" end with next temparr = split("未知 可移动磁盘 本地磁盘 网络驱动器 光盘 ram磁盘 ") s.i = "┏[分区信息]━━━━━━━━━━━━━━━━━━━━━━━━━━━━┉" for each tempobj1 in createobject("scripting.filesystemobject").drives with tempobj1 if .isready then pts = int(.freespace / .totalsize * 100) s.i = "┇盘符:" & .driveletter & " 文件系统:" & .filesystem & " 类型:" & temparr(.drivetype) & " 卷标:" & .volumename s.i = "┇" & " 空闲率:" & pts & "% " & string((100 - pts) / 5, "■") & string(pts / 5, "□") else s.i = "┇盘符:" & .driveletter & " 磁盘未准备好!" s.i = "┇" & " 空闲率:0% " & "≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡" end if end with next s.i = "┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┉" disk = s end function function sound() on error resume next s.i = "☆[声卡]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_sounddevice") with tempobj s.i = "┣名称/标签:" & .name & "/" & .caption s.i = "┇id :" & .deviceid s.i = "┇制造商 :" & .manufacturer end with next s.i = "┗━━━━━━━━━━━━━┉" sound = s end function function network() on error resume next s.i = "☆[网卡]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.execquery("select * from win32_networkadapter where physicaladapter = 'true'") with tempobj s.i = "┣[网卡:" & space(3 - len(.index)) & .index & "]━━━━━━━━┉" s.i = "┇标签 :" & .caption s.i = "┇pnpdid:" & .pnpdeviceid s.i = "┇制造商:" & .manufacturer s.i = "┇速率 :" & iif(typename(.speed) = "null", false, .speed / 10000 & "bps") s.i = "┇启用 :" & .netenabled s.i = "┇服务名:" & .servicename end with next s.i = "┗━━━━━━━━━━━━━┉" network = s end function function battery() on error resume next temparr1 = split(" 放电 交流电 充满 低 临界 充电 充电>高 充电>低 充电>临界 未定义 部分充电") temparr2 = split(" 其他 未知 铅酸 镉镍 镍金属氢化物 锂离子 锌空气 锂聚合物") s.i = "☆[内部电池]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_battery") with tempobj s.i = "┣名称/标签:" & .name & "/" & .caption s.i = "┇id :" & .deviceid s.i = "┇pnpdid :" & .pnpdeviceid s.i = "┇充电时间 :" & .batteryrechargetime s.i = "┇状态 :" & temparr1(.batterystatus) s.i = "┇材料 :" & temparr2(.chemistry) end with next s.i = "┗━━━━━━━━━━━━━┉" battery = s end function function portablebattery() on error resume next temparr1 = split(" 其他 未知 充满 低 临界 充电 充电>高 充电>低 充电>临界 未定义 部分充电") temparr2 = split(" 其他 未知 铅酸 镉镍 镍金属氢化物 锂离子 锌空气 锂聚合物") s.i = "☆[便携电池]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_portablebattery") with tempobj s.i = "┣名称/标签:" & .name & "/" & .caption s.i = "┇id :" & .deviceid s.i = "┇pnpdid :" & .pnpdeviceid s.i = "┇制造商 :" & .manufacturer s.i = "┇预计剩余 :" & .estimatedchargeremaining s.i = "┇预计时间 :" & .estimatedruntime s.i = "┇电源管理 :" & .powermanagementsupported s.i = "┇位置 :" & .location s.i = "┇智能电池 :" & .smartbatteryversion s.i = "┇材料 :" & temparr2(.chemistry) end with next s.i = "┗━━━━━━━━━━━━━┉" portablebattery = s end function function usb() on error resume next s.i = "☆[usb坞]" s.i = "┏━━━━━━━━━━━━━┉" for each tempobj in wmi.instancesof("win32_usbcontroller") with tempobj s.i = "┣标签 :" & .caption s.i = "┇id :" & .deviceid s.i = "┇pnpdid:" & .pnpdeviceid s.i = "┇制造商:" & .manufacturer end with next s.i = "┗━━━━━━━━━━━━━┉" usb = s end function end class '---- '输出 sub print(byval texts) wscript.stdout.write texts end sub sub echo(byval geom_tempdata) wscript.echo geom_tempdata end sub '输出:覆盖行,空白长度 sub printc(byval texts, byval lennum) wscript.stdout.write chr(13) & texts & string(lennum, " ") end sub '输出,+换行 sub printl(byval texts) wscript.stdout.writeline(texts) end sub '输入 function input() input = wscript.stdin.readline end function function iif(byval geom_tf, byval geom_t, byval geom_f) if geom_tf = true then iif = geom_t else iif = geom_f end function 'iif真 function tif(byval geom_tf, byval geom_t) if geom_tf = true then tif = geom_t end function 'iif假 function fif(byval geom_tf, byval geom_f) if geom_tf = false then fif = geom_f end function
运行效果: