HardwareInfo.vbs 獲取硬件信息的VBS代碼

PC教程網】關于HardwareInfo.vbs 獲取硬件信息的VBS代碼_vbs獲取sap信息欄消息介紹:教程實例 代碼如下: '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,下面小編為您針對HardwareInfo.vbs 獲取硬件信息的VBS代碼進行分享:

教程實例 代碼如下:

'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= "————————————主板信息————————————"  & 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"
    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


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

相關教程

javascript 硬盤序列號+其它硬件信息

看了看別的資料有提取CPU,MAC的現成代碼卻沒有硬盤序列號,找了好久才找到提取硬盤序列號的參數。于是自己給補上了。 html head title提取硬盤序列號/title script function disk() {//硬盤序列 …

C#編程實現動態改變配置文件信息的方法

本文實例講述了C#編程實現動態改變配置文件信息的方法。分享給大家供大家參考,具體如下: 配置文件實際上就是一個XML文件,所以我們可以使用XmlDocument來進行操作。 代碼如下: …

C++訪問注冊表獲取已安裝軟件信息列表示例代碼

C++訪問注冊表獲取已安裝軟件信息列表示例代碼

教程實例 代碼如下: // --------------------------------------------------------------- // FlieNmae: // SofInfo.h // Remark: // 通過讀取注冊表獲得本機已安裝軟件信息。 // --------------------------------------------- …

利用shell刪除數據表中指定信息和字段對應的文件

利用mysql shell命令讀取數據庫信息,刪除指定字段,以及字段對應的文件,適用Linux平臺。 前面變量定義為數據基本配置 教程實例 代碼如下: #!/bin/bash #Program # delete the database'info whick …

C#獲取指定文件著作權信息的方法

本文實例講述了C#獲取指定文件著作權信息的方法。分享給大家供大家參考。具體分析如下: C#獲得指定文件的著作權信息,通過FileVersionInfo可以獲得很多關于文件的信息,包括著作權 …

Node.js 去掉種子(torrent)文件里的邪惡信息

Node.js 去掉種子(torrent)文件里的邪惡信息

2012 年,一部名為 ABS-130 的日本影片引起了網絡的震動,網絡上紛紛出現了 “當初求種像條狗,如今*完嫌人丑”的現象,成為了 2012 年互聯網的一件大事件。 2014年,凈網行動如火如荼 …

内蒙古十一选五任五推荐号