当前位置:首页 > 科技 >

vbs获取系统硬件信息小脚本

发布时间:2017-09-09 10:46:56

vbs获取系统硬件信息小脚本 工作需要,需要获取win服务器的硬件信息,提交给一api 接口,最后用vbs实现了功能,主要是用到了WMI

发包是调用curl.exe来实现的,代码如下:

REM '获取IP地址' REM '判断DNS是否为空,判断IP地址开头是否为10或192' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled=TRUE",,48) For Each objItem in colItems If isNULL(objItem.DNSServerSearchOrder) Then Else IPX=objItem.IPAddress(0) LefIP=split(IPX,".")(0) If LefIP="10" OR LefIP="192" Then IP=IPX Wscript.Echo "ip:" & IP End If End If Next REM '获取SN号' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_BIOS",,48) For Each objItem in colItems SN=objItem.SerialNumber Wscript.Echo "Sn: " & SN Next REM '获取CPU信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_Processor",,48) For Each objItem in colItems Processor=objItem.Name Wscript.Echo "Processors: " & Processor Next REM '获取内存信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_ComputerSystem",,48) For Each objItem in colItems Memory= Round(objItem.TotalPhysicalMemory/1024^3) & "GB" Wscript.Echo "Memory: " & Memory Next REM '获取硬盘信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_DiskDrive",,48) For Each objItem in colItems Disk=objItem.Model Wscript.Echo "Disk: " & Disk Next REM '获取电脑品牌' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_BaseBoard",,48) For Each objItem in colItems Pinpai=objItem.Manufacturer Next REM '获取Summary信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_BaseBoard",,48) For Each objItem in colItems Product=objItem.Product Summary=Pinpai & " " & Product & "," & Processor & "," & Memory Wscript.Echo "Summary: " & Summary Next REM '获取Chipset信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_Processor",,48) For Each objItem in colItems Chipset=objItem.Caption Wscript.Echo "Chipset: " & Chipset Next REM '获取系统类型' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_OperatingSystem",,48) For Each objItem in colItems OS=objItem.Caption Wscript.Echo "OS: " & OS Next REM '获取BIOS信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_BIOS",,48) For Each objItem in colItems If isNull(objItem.BIOSVersion) Then Wscript.Echo "BIOS: " Else BIOS=Join(objItem.BIOSVersion,",") Wscript.Echo "BIOS: " & BIOS End If Next REM '获取计算机名' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_ComputerSystem",,48) For Each objItem in colItems Hostname=objItem.DNSHostName Wscript.Echo "Hostname:" & Hostname Next REM '获取MAC地址' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48) For Each objItem in colItems Macaddress=objItem.MACAddress Wscript.Echo "MACAddress: " & Macaddress Next REM '获取Network信息' strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") Set colItems = objWMIService.ExecQuery( _ "SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True",,48) For Each objItem in colItems Network=Mid(objItem.Caption,InStr(objItem.Caption,"]")+1) & " " & Macaddress Wscript.Echo "Network: " & Network Next REM 'curl发包' Dim Info Info="Summary: " & Summary & Chr(13) & "Processors: " & Processor & Chr(13) & "Memory: " & Memory & Chr(13) & "Disk: " & Disk & Chr(13) & "Chipset: " & Chipset & Chr(13) & "Network: " & Network & Chr(13) & "BIOS: " & BIOS dim curlcmd dim cmdstr set curlcmd=Createobject("wscript.shell") cmdstr = "curl.exe -d ""ip=" & IP & "&sn=" & SN & "&info=" & Info & """ " curlcmd.run cmdstr

企业建站2800元起,携手武汉肥猫科技,做一个有见地的颜值派!更多优惠请戳:黄石SEO http://huangshi.raoyu.net