Hardware_ Info. VBS VBS code for obtaining hardware information

Time:2022-5-6
Copy codeThe code is 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
        OSx = oOS.Caption &” ” & oOS.CSDVersion  & vbCrLf
Next
BBX = “—————————-” — mainboard 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 Each oBios In Bios
BBx = BBx _
& BIOS vendor: & 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) > 10 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 _
& number of cores: & 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 usage: & 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 & “L1 cache:” & objcache MaxCacheSize & “KB (L1 data + L1 cache)” & vbcrlf
        case “L2-Cache”
Cpux = cpux & “L2 cache:” & objcache MaxCacheSize & ” KB” & vbCrLf
        case “L3-Cache”
Cpux = cpux & “L3 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 & “slot” & 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 usage: & formatpercent ((zl-ky) / ZL) & vbcrlf
Set Memorys = Nothing:Set MemKY = Nothing

VX = “—————————-” — graphics card 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 Video
        Vx = Vx _
& graphics card name: & ovideo Name                                    & vbCrLf _
& manufacturer: & ovideo AdapterCompatibility                    & vbCrLf _
& physical video 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

Hard disk information
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 & “hard disk” & I & “model:” & Oide Caption                   & vbCrLf _
& vbtab & “nominal capacity:” & round (Oide. Size / 1000000000) & “GB” & vbcrlf_
& vbtab & “actual capacity:” & round (Oide. Size / 1073741824) & “GB” & vbcrlf_
& vbtab & “number of cylinders:” & Oide TotalCylinders                & vbCrLf _
& vbtab & “number of heads:” & Oide TotalHeads                    & vbCrLf _
& vbtab & “number of sectors per track:” & Oide SectorsPerTrack               & vbCrLf _
& vbtab & “sector size:” & Oide BytesPerSector                & vbCrLf _
& vbtab & “total 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 & “”, 11) & left (old. Filesystem & “”, 6) & “of:”_
“LD (right)” & 1074, 416 “_
& 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 & “network card name:” & onet Name & vbtab & active & vbcrlf
           Else
Nx = NX & “network card name:” & onet Name & vbtab & “idle state” & 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 (“save to file?”, 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”
    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 & “——————–” — 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 & “time required for CPU 2 million square root calculations:” & aruntime & “milliseconds” & vbcrlf
    T1 = Timer()
    For I = 1 To 6000000
        Tempvalue= 1 + 1
    Next
    T2 = Timer()
    bRunTime = FormatNumber((T2-T1)*1000,2)
Nummsg = nummsg & “time required for CPU 6 million addition calculations:” & breuntime & “milliseconds” & vbcrlf
    JZCS = NumMsg
End Function


CMD call method

Copy codeThe code is as follows:


@echo off
for /f “delims=*” %%a In (‘Cscript //Nologo “Hardware_Info.vbs”^|find “:”‘) do echo %%a

 

: create a new backup folder in the first partition of the second hard disk
For / F “tokens = 2, *”%% a in (‘cscript / / nologo “hardware_info. VBS” ^|findstr “partition status”) do(
    if %%a#==1# for /f “tokens=1” %%i In (“%%b”) do MD “%%i\Backup”)
pause