标题: [原创] VBS硬件信息 Hardware_Info.vbs [打印本页]
作者: fastslz 时间: 2011-6-29 18:58 标题: VBS硬件信息 Hardware_Info.vbs
本帖最后由 fastslz 于 2011-8-28 15:28 编辑
代码没有技术水准,网上搜索有一大堆类似代码,关键是中文描述方式
支持多个硬盘、显卡、内存、声卡、网卡,CPU超频识别
支持cmd调用- 'Hardware_Info.vbs v1.1 BY: fastslz http://bbs.bathome.net
- On Error Resume Next
- Dim WMI,WS,Fso
- Set WMI = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
- Set cOSs = WMI.ExecQuery("Select * from Win32_OperatingSystem")
- For Each oOS in cOSs
- OSx = oOS.Caption &" " & oOS.CSDVersion & vbCrLf
- Next
- BBx= "————————————主板信息————————————" & vbCrLf
- Set Board = WMI.InstancesOf("Win32_BaseBoard")
- Set Bios = WMI.InstancesOf("Win32_Bios")
- For Each oBoard In Board
- BBx = BBx _
- & "主板名称: " & oBoard.Product &vbTab & oBoard.Version & vbCrLf _
- & "制造厂商: " & oBoard.Manufacturer & vbCrLf
- Next
- For Each oBios In Bios
- BBx = BBx _
- & "BIOS厂商: " & oBios.Manufacturer & vbCrLf _
- & "BIOS日期: " & FormatDateTime(wDate(Trim(oBios.ReleaseDate)),1) & vbCrLf _
- & "BIOS版本: " & oBios.SMBIOSBIOSVersion & vbCrLf _
- & "OEM 版本: " & oBios.Version & vbCrLf
- Next
- Set Bios = Nothing:Set Board = Nothing
-
- CPUx = "———————————处理器信息———————————" & vbCrLf
- Set CPUs = WMI.InstancesOf("Win32_Processor")
- Set Caches = WMI.InstancesOf("Win32_CacheMemory")
- For Each ObjCPU In CPUs
- MCS = ObjCPU.MaxClockSpeed :CCS = ObjCPU.CurrentClockSpeed
- If ObjCPU.MaxClockSpeed Mod 2 = 1 Then MCS = CCS + 1
- If ObjCPU.CurrentClockSpeed Mod 2 = 1 Then CCS = CCS + 1
- OC = QOC(CCS,MCS)
- If (OC-MCS) > 10 and (OC-MCS) > 0 Then OCLC = " 超频比率: " & FormatPercent((OC-MCS)/MCS)
- If (OC-MCS) < -10 and (OC-MCS) < 0 Then OCLC = " 降频比率: " & FormatPercent((OC-MCS)/MCS)
- CPUx = CPUx _
- & "CPU 名称: " & Trim(ObjCPU.Name) & vbCrLf _
- & "CPU 构架: " & ObjCPU.Description & vbCrLf _
- & "制造厂商: " & ObjCPU.Manufacturer & vbCrLf _
- & "接口规格: " & ObjCPU.SocketDesignation & vbCrLf _
- & "CPU 数量: " & ObjCPU.CpuStatus & vbCrLf _
- & "核心数量: " & ObjCPU.NumberOfCores & vbCrLf _
- & "线程数量: " & ObjCPU.NumberOfLogicalProcessors & vbCrLf _
- & "地址位宽: " & ObjCPU.AddressWidth & " Bit" & vbCrLf _
- & "数据位宽: " & ObjCPU.DataWidth & " Bit" & vbCrLf _
- & "CPU 电压: " & ObjCPU.CurrentVoltage / 10 & "V" & vbCrLf _
- & "外部频率: " & ObjCPU.ExtClock & " MHz" & vbCrLf _
- & "当前频率: " & OC & " MHz" & OCLC & vbCrLf _
- & "原始频率: " & MCS & " MHz" & vbCrLf _
- & "CPU 使用: " & ObjCPU.LoadPercentage & "%" & vbCrLf
- Next
- Function QOC(CCS,MCS)
- If CCS = MCS Then
- Set wReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
- wReg.GetDWORDValue &H80000002,"HARDWARE\DESCRIPTION\System\CentralProcessor\0","~MHz",strValue
- OC = strValue :Set wReg = Nothing
- Else
- OC = CCS
- End If
- QOC = OC :If QOC Mod 2 = 1 Then QOC = QOC + 1
- End Function
- For Each ObjCache In Caches
- If objCache.MaxCacheSize > 0 Then
- Select Case objCache.Purpose
- case "L1-Cache"
- CPUx = CPUx & "一级缓存: " & objCache.MaxCacheSize & "KB (L1数据+L1缓存)" & vbCrLf
- case "L2-Cache"
- CPUx = CPUx & "二级缓存: " & objCache.MaxCacheSize & " KB" & vbCrLf
- case "L3-Cache"
- CPUx = CPUx & "三级缓存: " & objCache.MaxCacheSize & " KB" & vbCrLf
- End Select
- End If
- Next
- Set Caches = Nothing:Set CPUs = Nothing
-
- Memx = "————————————内存信息————————————" & vbCrLf
- Set Memorys = WMI.InstancesOf("Win32_PhysicalMemory")
- Set MemKY = WMI.InstancesOf("Win32_OperatingSystem")
- For Each aKY In MemKY
- ZL = aKY.TotalVisibleMemorySize
- KY = aKY.FreePhysicalMemory
- Next
- Mems = 0:Memc = 0
- Types = Array("Unknown","Other","DRAM","Synchronous DRAM","Cache DRAM","EDO","EDRAM","VRAM","SRAM", "RAM", _
- "ROM","Flash","EEPROM","FEPROM","EPROM","CDRAM","3DRAM","SDRAM","SGRAM","RDRAM","DDR","DDR2")
- For Each Mem In Memorys
- For i = 0 To UBound(Types)
- If Mem.MemoryType = i Then MemType = Types(i) :End If
- Next
- For j = 0 To 6
- Select Case Mem.Tag
- case "Physical Memory " & j
- Mems = Mems+(Mem.Capacity)
- Memx = Memx &"插槽" & Mem.DeviceLocator & ": " & Round(Mem.Capacity/1048576) &" MB " _
- & MemType & "-" & Mem.Speed & "MHz" & " 数据带宽" & Mem.DataWidth _
- & "Bit" & " 总带宽" & Mem.TotalWidth &"Bit" & vbCrLf
- End Select
- Next
- Next
- Memx = Memx _
- & "内存安装: "& Round(Mems/1048576)&" MB " & vbCrLf _
- & "内存总量: "& Round(ZL/1024)& " MB" & vbCrLf _
- & "内存可用: "& Round(KY/1024)& " MB" & vbCrLf _
- & "内存使用率: " &FormatPercent((ZL-KY)/ZL)& vbCrLf
- Set Memorys = Nothing:Set MemKY = Nothing
-
- Vx= "————————————显卡信息————————————" & vbCrLf
- Set cVID = WMI.ExecQuery("SELECT DeviceID FROM Win32_VideoController")
- For Each oVID In cVID
- Set Video = WMI.ExecQuery("SELECT * FROM Win32_VideoController WHERE DeviceID='"& oVID.DeviceID &"'")
- For Each oVideo In Video
- Vx = Vx _
- & "显卡名称: " & oVideo.Name & vbCrLf _
- & "制造厂商: " & oVideo.AdapterCompatibility & vbCrLf _
- & "物理显存: " & Round(oVideo.AdapterRAM/1048576)&" MB " & vbCrLf _
- & "显示模式: " & oVideo.CurrentHorizontalResolution &" X " _
- & oVideo.CurrentVerticalResolution &" "_
- & oVideo.CurrentBitsPerPixel &"Bit " _
- & oVideo.CurrentRefreshRate &"Hz" & vbCrLf
- Next
- Next
- Set Video = Nothing:Set cVID = Nothing
-
- Dx= "————————————硬盘信息————————————" & vbCrLf
- Set IDE = WMI.ExecQuery("Select * from Win32_DiskDrive WHERE InterfaceType='IDE'")
- Set cPPP = WMI.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk")
- For Each oIDE In IDE
- For i = 0 To IDE.Count
- Select Case oIDE.Index
- Case i
- For Each oPPP In cPPP
- If InStr(oPPP.Name, i) Then vName = oPPP.Name
- Next
- Dx = Dx & "硬盘" & i &"型号:" & oIDE.Caption & vbCrLf _
- & vbTab & "标称容量: " & Round(oIDE.Size/1000000000) &" GB" & vbCrLf _
- & vbTab & "实际容量: " & Round(oIDE.Size/1073741824) &" GB" & vbCrLf _
- & vbTab & "柱面数: " & oIDE.TotalCylinders & vbCrLf _
- & vbTab & "磁头数: " & oIDE.TotalHeads & vbCrLf _
- & vbTab & "每道扇区数: " & oIDE.SectorsPerTrack & vbCrLf _
- & vbTab & "扇区大小: " & oIDE.BytesPerSector & vbCrLf _
- & vbTab & "总扇区数: " & oIDE.TotalSectors & vbCrLf _
- & vbTab & "分区状态: " & vName & vbCrLf
- DevID = Replace(oIDE.DeviceID, "\", "\\")
- Set cDP = WMI.ExecQuery("ASSOCIATORS OF {Win32_DiskDrive.DeviceID="""& DevID &"""}" _
- & "WHERE AssocClass = Win32_DiskDriveToDiskPartition")
- For Each oDP In cDP
- Set cLD = WMI.ExecQuery("ASSOCIATORS OF {Win32_DiskPartition.DeviceID="""& oDP.DeviceID &"""}" _
- & "WHERE AssocClass = Win32_LogicalDiskToPartition")
- For Each oLD In cLD
- Dx = Dx _
- & vbTab & oLD.DeviceID &" " & Left(oLD.VolumeName&" " ,11) & Left(oLD.FileSystem&" " ,6) & "共:" _
- & Right(" "&Round(oLD.Size/1073741824,1),6) &" GB 可用:" _
- & Right(" "&Round(oLD.FreeSpace/1073741824,1),6) &" GB 已用:" _
- & Right(" "&Round((oLD.Size-oLD.FreeSpace)/1073741824,1),6)&" GB" & vbCrLf
- Next
- Next
- End Select
- Next
- Next
- Set cLD = Nothing:Set cDP = Nothing:Set IDE = Nothing:Set cDP = Nothing:Set cPPP = Nothing
-
- Sx= "————————————声卡信息————————————" & vbCrLf
- Set cSD = WMI.ExecQuery("SELECT * FROM Win32_SoundDevice")
- For Each oSD In cSD
- Sx = Sx & "声卡名称: " & oSD.ProductName & vbCrLf
- Next
- Set cSD = Nothing
- Nx= "————————————网卡信息————————————" & vbCrLf
- Set cNet = WMI.ExecQuery("Select * from Win32_NetworkAdapter WHERE PhysicalAdapter ='TRUE'")
- If CStr(cNet.Count) < 0 Then
- Set cNet = WMI.ExecQuery("Select * from Win32_NetworkAdapter WHERE PNPDeviceID Like 'PCI%%' or PNPDeviceID Like 'USB%%'")
- For Each oNet In cNet
- If oNet.NetConnectionStatus > 0 Then
- Nx = Nx & "网卡名称: "& oNet.Name & vbCrLf
- Else
- Nx = Nx & "网卡名称: "& oNet.Name & vbCrLf
- End If
- Next
- Else
- For Each oNet In cNet
- If oNet.NetEnabled = TRUE Then
- Nx = Nx & "网卡名称: "& oNet.Name & vbTab & "活跃状态" & vbCrLf
- Else
- Nx = Nx & "网卡名称: "& oNet.Name & vbTab & "空闲状态" & vbCrLf
- End If
- Next
- End If
- Set cNet = Nothing
-
- If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
- MsgBox OSx & BBx & CPUx & Memx ,,"Hardware_Info.vbs v1.0 BY: fastslz"
- MsgBox Vx & Sx & Nx ,,"Hardware_Info.vbs v1.0 BY: fastslz"
- MsgBox Dx ,, "Hardware_Info.vbs v1.0 BY: fastslz"
- MsgN = MsgBox ("是否保存到文件?" , 32+4 , "Hardware_Info.vbs v1.0 BY: fastslz")
- If MsgN = 6 Then JZCSx = JZCS :wInfo
- Else
- WScript.Echo OSx & BBx & CPUx & Memx & Vx & Sx & Nx & Dx
- End If
- Set WMI = Nothing
-
- Sub wInfo()
- Set WS = CreateObject("WScript.Shell")
- Set Fso = CreateObject("Scripting.FileSystemObject")
- aFile = WS.CurrentDirectory &"\"& WS.ExpandEnvironmentStrings("%COMPUTERNAME%")&"_Hardware_Info.txt"
- Set HInfo = Fso.CreateTextFile(aFile , True)
- HInfo.WriteLine "Hardware_Info.vbs BY: fastslz http://bbs.bathome.net"
- HInfo.WriteLine OSx & BBx & CPUx & Memx & Vx & Sx & Nx & Dx & JZCSx
- HInfo.Close
- WS.Run Chr(34) & aFile & Chr(34)
- Set WS = Nothing:Set Fso = Nothing:Set HInfo = Nothing
- End Sub
-
- Function wDate(nD)
- If Not IsNull(nD) Then
- wDate = CDate(Mid(nD,5,2)&"/"&Mid(nD,7,2)&"/"&Left(nD,4)&" "&Mid(nD,9,2)&":"&Mid(nD,11,2)&":"&Mid(nD,13,2))
- End If
- End Function
-
- Function JZCS()
- NumMsg = vbCrLf & "———————————简易CPU基准测试———————————" & vbCrLf
- Dim I,T1,T2,Tempvalue,aRunTime,bRunTime
- T1 = Timer()
- For I = 1 To 2000000
- Tempvalue= 2^0.5
- Next
- T2 = Timer()
- aRunTime = FormatNumber((T2-T1)*1000,2)
- NumMsg = NumMsg & "CPU 200万次开方计算所需时间:" &aRunTime&" 毫秒" & vbCrLf
- T1 = Timer()
- For I = 1 To 6000000
- Tempvalue= 1 + 1
- Next
- T2 = Timer()
- bRunTime = FormatNumber((T2-T1)*1000,2)
- NumMsg = NumMsg & "CPU 600万次加法计算所需时间:"&bRunTime&" 毫秒" & vbCrLf
- JZCS = NumMsg
- End Function
复制代码
作者: fastslz 时间: 2011-6-29 19:02
本帖最后由 fastslz 于 2011-6-29 20:06 编辑
cmd调用方法- @echo off
- for /f "delims=*" %%a In ('Cscript //Nologo "Hardware_Info.vbs"^|find ":"') do echo %%a
-
- :在第二个硬盘第一个分区新建Backup文件夹
- for /f "tokens=2,*" %%a In ('Cscript //Nologo "Hardware_Info.vbs"^|findstr "分区状态"') do (
- if %%a#==1# for /f "tokens=1" %%i In ("%%b") do MD "%%i\Backup")
- pause
复制代码
Hardware_Info.vbs BY: fastslz http://bbs.bathome.net
..................................
————————————主板信息————————————
主板名称: P5QL PRO Rev 1.xx
制造厂商: ASUSTeK Computer INC.
BIOS厂商: American Megatrends Inc.
BIOS日期: 2009年7月1日
BIOS版本: 1004
OEM 版本: _ASUS_ - 7000901
———————————处理器信息———————————
CPU 名称: Intel(R) Core(TM)2 Quad CPU Q8300 @ 2.50GHz
CPU 构架: Intel64 Family 6 Model 23 Stepping 10
制造厂商: GenuineIntel
接口规格: LGA775
CPU 数量: 1
核心数量: 4
线程数量: 4
地址位宽: 64 Bit
数据位宽: 64 Bit
CPU 电压: 1.3V
外部频率: 402 MHz
当前频率: 3000 MHz 超频比率: 20.00%
原始频率: 2500 MHz
CPU 使用: 2%
一级缓存: 128KB (L1数据+L1缓存)
二级缓存: 4096 KB
————————————内存信息————————————
插槽DIMM0: 2048 MB DDR-1066MHz 数据带宽64Bit 总带宽64Bit
插槽DIMM2: 2048 MB DDR-1066MHz 数据带宽64Bit 总带宽64Bit
内存安装: 4096 MB
内存总量: 4095 MB
内存可用: 2039 MB
内存使用率: 50.22%
————————————显卡信息————————————
显卡名称: NVIDIA GeForce GT 220
制造厂商: NVIDIA
物理显存: 512 MB
显示模式: 1440 X 900 32Bit 60Hz
————————————声卡信息————————————
声卡名称: NVIDIA High Definition Audio
声卡名称: Realtek High Definition Audio
声卡名称: NVIDIA High Definition Audio
声卡名称: NVIDIA High Definition Audio
声卡名称: NVIDIA High Definition Audio
————————————网卡信息————————————
网卡名称: Atheros AR8121/AR8113/AR8114 PCI-E Ethernet Controller 活跃状态
————————————硬盘信息————————————
硬盘1: Maxtor 6L080P0 ATA Device 固件: BAJ41G20
标称容量: 82 GB 实际容量: 76 GB
柱面数: 9964 磁头数: 255
每道扇区数: 63 扇区大小: 512
总扇区数: 160071660
分区状态: 1 J: K:
.....................................
硬盘0: ST3500418AS 固件: CC49
标称容量: 500 GB 实际容量: 466 GB
柱面数: 60801 磁头数: 255
每道扇区数: 63 扇区大小: 512
总扇区数: 976768065
分区状态: 0 C: D: E:
.....................................
———————————简易CPU基准测试———————————
CPU 200万次开方计算所需时间:593.75 毫秒
CPU 600万次加法计算所需时间:375.00 毫秒
作者: 极品小猫 时间: 2012-11-5 00:05
这个太给力了, 没想到找个自动改移动设备盘符的方法还发现了这么好的东西
作者: yu2n 时间: 2012-11-5 23:06
WMI,不错。
作者: zzh197206 时间: 2012-11-26 11:07
很不错的东西
作者: 9zhmke 时间: 2013-12-7 12:39
网卡那一段有些冗杂,一是可以精简点,二则是判断活跃网卡那里是不是写错了?
If CStr(cNet.Count) < 0 Then....应该写成 If CStr(cNet.Count) < 1 Then
这一段可以精简成:
On Error Resume Next
Set cNet = WMI.ExecQuery("Select * from Win32_NetworkAdapter WHERE PNPDeviceID Like 'PCI%%' or PNPDeviceID Like 'USB%%'")
For Each oNet In cNet
If CStr(cNet.Count) > 0 Then
Nx = Nx & "网卡名称: "& oNet.Name & vbTab & "活跃状态" & vbCrLf
Else
Nx = Nx & "网卡名称: "& oNet.Name & vbCrLf
End If
Next
On Error goto 0
Set cNet = Nothing
作者: fastslz 时间: 2014-1-1 21:58
回复 6# 9zhmke
开始我也是不绕弯弯的,这样做只是因为多个网卡状态下区分,正在使用中的网卡即活跃空闲状态
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |