Hardware_info.vbs the VBS code to obtain hardware information _vbs

Source: Internet
Author: User
Tags chr

Copy Code code as follows:

' Hardware_info.vbs v1.1 By:fastslz
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
OS X = oos.caption & "" & Oos.csdversion & VbCrLf
Next
bbx= "———————————— motherboard information ————————————" & VbCrLf
Set Board = WMI. InstancesOf ("Win32_baseboard")
Set Bios = WMI. InstancesOf ("Win32_BIOS")
For each oboard in Board
BBx = BBx _
& "motherboard name:" & oboard.product &vbtab & oboard.version & VbCrLf _
& "Manufacturer:" & Oboard.manufacturer & VbCrLf
Next
For the Obios in Bios
BBx = BBx _
& "BIOS Manufacturer:" & Obios.manufacturer & VbCrLf _
& "BIOS Date:" & FormatDateTime (Wdate) (Trim (obios.releasedate), 1) & VbCrLf _
& "BIOS version:" & Obios.smbiosbiosversion & VbCrLf _
& "OEM version:" & Obios.version & VbCrLf
Next
Set Bios = Nothing:set Board = Nothing

Cpux = "——————————— processor information ———————————" & 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) > Ten and (Oc-mcs) > 0 Then OCLC = "overclocking ratio:" & FormatPercent ((OC-MCS)/mcs)
If (OC-MCS) < -10 and (Oc-mcs) < 0 Then OCLC = "Frequency reduction ratio:" & FormatPercent ((OC-MCS)/mcs)
Cpux = Cpux _
& "CPU Name:" & Trim (Objcpu.name) & VbCrLf _
& "CPU Architecture:" & Objcpu.description & VbCrLf _
& "Manufacturer:" & Objcpu.manufacturer & VbCrLf _
& "Interface Specification:" & Objcpu.socketdesignation & VbCrLf _
& "Number of CPUs:" & Objcpu.cpustatus & VbCrLf _
& "Core quantity:" & Objcpu.numberofcores & VbCrLf _
& "Number of Threads:" & Objcpu.numberoflogicalprocessors & VbCrLf _
& "Address bit width:" & objcpu.addresswidth & "Bit" & vbCrLf _
& "Data bit width:" & objcpu.datawidth & "Bit" & vbCrLf _
& "CPU voltage:" & OBJCPU.CURRENTVOLTAGE/10 & "V" & vbCrLf _
& "External frequency:" & Objcpu.extclock & "MHz" & vbCrLf _
& "Current frequency:" & OC & "MHz" & OCLC & VbCrLf _
& "Original frequency:" & MCS & "MHz" & vbCrLf _
& "CPU use:" & 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 & First-level cache: & Objcache.maxcachesize & KB (L1 data +l1 cache) "& VbCrLf
Case "L2-cache"
Cpux = Cpux & "Level Two cache:" & objcache.maxcachesize & "KB" & VbCrLf
Case "L3-cache"
Cpux = Cpux & "Level Three cache:" & objcache.maxcachesize & "KB" & VbCrLf
End Select
End If
Next
Set caches = Nothing:set CPUs = Nothing

MEMX = "———————————— Memory information ————————————" & 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 & "Slots" & Mem.devicelocator & ": & Round (mem.capacity/1048576) &" MB "_
& Memtype & "-" & Mem.speed & "MHz" & "Data Bandwidth" & Mem.datawidth _
& "Bit" & "Total Bandwidth" & Mem.totalwidth & "Bit" & VbCrLf
End Select
Next
Next
Memx = Memx _
& "Memory Installation:" & Round (mems/1048576) & "MB" & vbCrLf _
& "Total Memory:" & Round (zl/1024) & "MB" & vbCrLf _
& "Memory available:" & Round (ky/1024) & "MB" & vbCrLf _
& "Memory Utilization:" &formatpercent (Zl-ky)/zl) & VbCrLf
Set Memorys = Nothing:set Memky = Nothing

vx= "———————————— Graphics Information ————————————" & 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
VX = VX _
& "video card name:" & Ovideo.name & VbCrLf _
& "Manufacturer:" & ovideo.adaptercompatibility & VbCrLf _
& "Physical Memory:" & Round (ovideo.adapterram/1048576) & "MB" & vbCrLf _
& "display mode:" & ovideo.currenthorizontalresolution & "X" _
& Ovideo.currentverticalresolution & "" _
& Ovideo.currentbitsperpixel & "Bit" _
& Ovideo.currentrefreshrate & "Hz" & VbCrLf
Next
Next
Set Video = Nothing:set Cvid = Nothing

dx= "———————————— Hard drive Information ————————————" & VbCrLf
Set IDE = WMI. ExecQuery ("select * from win32_diskdrive WHERE interfacetype= ' IDE ')"
Set CPPP = WMI. ExecQuery ("SELECT * from Win32_perfrawdata_perfdisk_physicaldisk")
For the 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 & "HDD" & I & "Model:" & Oide.caption & VbCrLf _
& VbTab & "Nominal capacity:" & Round (oide.size/1000000000) & "GB" & vbCrLf _
& VbTab & "actual capacity:" & Round (oide.size/1073741824) & "GB" & vbCrLf _
& VbTab & "cylinder number:" & Oide.totalcylinders & VbCrLf _
& VbTab & "head number:" & Oide.totalheads & VbCrLf _
& VbTab & "per number of sectors:" & Oide.sectorspertrack & VbCrLf _
& VbTab & "Sector size:" & Oide.bytespersector & VbCrLf _
& VbTab & "Total number of Sectors:" & Oide.totalsectors & VbCrLf _
& VbTab & "Partition status:" & 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&" ", one) & Left (old.filesystem&" " , 6) & "Total:" _
& Right ("" &round (old.size/1073741824,1), 6) & "GB available:" _
& Right ("" "&round (old.freespace/1073741824,1), 6) &" GB used: "_
& 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= "———————————— sound card information ————————————" & VbCrLf
Set CSD = WMI. ExecQuery ("SELECT * from Win32_sounddevice")
For each OSD in CSD
SX = SX & "sound card name:" & Osd.productname & VbCrLf
Next
Set CSD = Nothing
nx= "———————————— Network card information ————————————" & 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 & "network card name:" & Onet.name & VbCrLf
Else
NX = NX & "network card name:" & Onet.name & VbCrLf
End If
Next
Else
For each oNet in CNet
If onet.netenabled = TRUE Then
NX = NX & "NIC Name:" & Onet.name & VbTab & "Active status" & VbCrLf
Else
NX = NX & "network card name:" & Onet.name & VbTab & "Idle state" & VbCrLf
End If
Next
End If
Set CNet = Nothing

If (Lcase (wscript.fullname,11) = "Wscript.exe") Then
    MsgBox OS X & BBx & Cpux ; Memx,, "Hardware_info.vbs v1.0 By:fastslz"
    MsgBox Vx & Sx & nx ,, "Hardware_info.vbs V 1.0 By:fastslz "
    MsgBox Dx," Hardware_info.vbs v1.0 By:fastslz "
    msgn = MSGB Ox ("Do you want to save to file?) ", 32+4," Hardware_info.vbs v1.0 By:fastslz ")
    If msgn = 6 Then jzcsx = Jzcs:winfo
   ;  Else
    wscript.echo OS & 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"
     hinfo.writeline X & BBx & Cpux & memx & Vx & Sx & Nx & Dx & JZCSX
     hinfo.close
    WS. Run Chr & Afile & Chr (a)
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 & "——————————— Simple CPU Benchmark ———————————" & 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 2 million-time root calculation time required:" &aRunTime& "milliseconds" & vbCrLf
T1 = Timer ()
For I = 1 to 6000000
Tempvalue= 1 + 1
Next
T2 = Timer ()
Bruntime = FormatNumber ((t2-t1) *1000,2)
nummsg = nummsg & "CPU 6 million-time addition calculation time:" &bRunTime& "milliseconds" & vbCrLf
Jzcs = nummsg
End Function


Cmd Invoke method
Copy Code code as follows:

@echo off
for/f "delims=*"%%a in (' Cscript//nologo "Hardware_info.vbs" ^|find ":" ') do echo%%a

: Create a new backup folder on the first partition of the second hard drive
for/f "tokens=2,*"%%a in (' Cscript//nologo "hardware_info.vbs" ^|FINDSTR "Partition State") Do (
If%%a#==1# for/f "Tokens=1"%%i in ("%%b") do MD "%%i\backup"
Pause

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.