首页 > 程序开发 > Web开发 > 其他 > 正文
vbs获取系统硬件信息小脚本
2013-11-24       个评论      
收藏    我要投稿
工作需要,需要获取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 & """ http://ams.nxadmin.com/api/hwinfo"
curlcmd.run cmdstr

 


点击复制链接 与好友分享!回本站首页
上一篇:image来提交
下一篇:Web应用中session的实现机制
相关文章
图文推荐
文章
推荐
点击排行

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训
版权所有: 红黑联盟--致力于做实用的IT技术学习网站