Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1761631
  • 博文数量: 234
  • 博客积分: 4966
  • 博客等级: 上校
  • 技术积分: 3322
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-13 01:03
文章分类

全部博文(234)

文章存档

2017年(2)

2016年(1)

2015年(8)

2014年(11)

2013年(44)

2012年(27)

2011年(22)

2010年(30)

2009年(37)

2008年(6)

2007年(45)

2006年(1)

分类:

2010-04-26 10:29:15

' *****************************************************************************
' TEST SCRIPT - 收集硬件信息.vbs
' *****************************************************************************
'  作用: 收集硬件信息
'  作者: brinkman
'  日期: 2010.4.26 09.25
'  Copyright (c) sunwill
' *****************************************************************************
 

'将在这个目录里以计算机名生成信息,请让这个目录具有可写权限
  On Error Resume Next
  SerVerPath = "硬件信息"
  '这里的保存路径可以为UNC网络路径()
  set wshshell=wscript.createobject("wscript.shell")
  '启动WMI服务
  wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,True
  wshshell.run ("%comspec% /c sc config  winmgmt start= auto"),0,True
  wshshell.run ("%comspec% /c net start winmgmt"),0
  wshshell.run ("%comspec% /c if not exist .\硬件信息 mkdir .\硬件信息"),0,True
  '2,5-10行为独自等待添加,15行中的.\硬件信息为上面变量中的路径,请根据需要修改。
  Dim objWMIService
  Set objWMIService = Getobject("winmgmts:\\.\root\cimv2")
  Dim objOSInfos, objOSInfo, OSInfo, ComputerName, OSVer
  Set objOSInfos = objWMIService.execQuery("Select * From win32_operatingsystem")
  For Each objOSInfo In objOSInfos
    OSInfo = objOSInfo.CSName & ","
    ComputerName = objOSInfo.CSName
    OSVer = objOSInfo.Version
    OSInfo = OSInfo & objOSInfo.Caption & " " & objOSInfo.CSDVersion & ","
    OSInfo  = "系统信息:" & OSInfo & Mid(CStr(objOSInfo.InstallDate),1,4) & "-" & _
              Mid(CStr(objOSInfo.InstallDate),5,2) & "-" & _
              Mid(CStr(objOSInfo.InstallDate),7,2)
  Next
 
  Dim objBoards, objBoard, BoardInfo
  Set objBoards = objWMIService.execQuery("Select * From Win32_BaseBoard")
  For each objBoard In objBoards
    BoardInfo = Trim(objBoard.Product) & ","
    BoardInfo = "主板型号:" & BoardInfo & Trim(objBoard.Manufacturer)
  Next
 
  Dim objCPUs, objCPU, CPUInfo
  Set objCPUs = objWMIService.execQuery("Select * From win32_processor")
  For each objCPU In objCPUs
    CPUInfo = Trim(objCPU.Name) & ","
    CPUInfo = CPUInfo & objCPU.ExtClock & ","
    CPUInfo = CPUInfo & objCPU.L2CacheSize & ","
    CPUInfo = "CPU型号:" & CPUInfo & objCPU.SocketDesignation
  Next
 
  Dim objMemorys, objMemory, MemoryInfo
  Set objMemorys = objWMIService.execQuery("Select * From Win32_PhysicalMemory")
  Redim arrMemory(1)
  For Each objMemory In objMemorys
    arrMemory(0) = arrMemory(0) + objMemory.capacity/1048576
    arrMemory(1) = arrMemory(1) & objMemory.Speed & "/" & objMemory.DeviceLocator & " "
  Next
  MemoryInfo = "内存容量:" & objMemorys.Count  & "条,共" & arrMemory(0) & "M," & arrMemory(1)
 
  Dim objDisks, objDisk, DiskInfo
  Set objDisks = objWMIService.execQuery("Select * From win32_diskdrive")
  For Each objDisk In objDisks
    DiskInfo = "硬盘容量:" & Trim(objDisk.Model)
    Exit For
  Next
 
  Dim objVideos, objVideo, VideoInfo
  Set objVideos = objWMIService.execQuery("Select * From win32_videocontroller")
  For Each objVideo In objVideos
    If Not IsNull(objVideo.VideoModeDescription) Then
        VideoInfo = Trim(objVideo.Description)
        VideoInfo = "显卡型号:" & VideoInfo & "(" & objVideo.AdapterRAM/1048576 & "M)"
    End If
  Next
 
  Dim objNetworks, objNetwork, objNetworks_2, objNetwork_2, NetWorkInfo
  NetWorkInfo = ""
  Set objNetworks = objWMIService.execQuery("Select * From Win32_NetworkAdapter")
  Set objNetworks_2 = objWMIService.execQuery("Select * From Win32_NetworkAdapterConfiguration")
  For Each objNetwork In objNetworks
    If objNetwork.Manufacturer <> "Microsoft" And Not Isnull(objNetwork.MACAddress) Then
      For Each objNetwork_2 In objNetworks_2
        If objNetwork_2.Index = objNetwork.Index Then
          NetWorkInfo = "网卡信息:" & objNetwork.Description & "," & objNetwork_2.IPAddress(0) & _
                        Space(17-Len(objNetwork_2.IPAddress(0))) & _
                        Replace(objNetwork_2.MACAddress,":","-")
          Exit For
        End If
      Next
      If NetWorkInfo <> "" Then Exit For
    End If
  Next
 
  '输出信息到文件
  Dim FSO, OutFile
  Set FSO = WScript.Createobject("Scripting.Filesystemobject")
  SerVerPath = FSO.GetAbsolutePathName(SerVerPath)
  Set OutFile = FSO.CreateTextFile(SerVerPath & "\" & ComputerName & ".txt",True)
  'OutFile.Writeline OSInfo & BoardInfo & CPUInfo & MemoryInfo & DiskInfo & VideoInfo & NetWorkInfo
  '以下信息由独自等待根据上面的输出改写的,方便查看。
  OutFile.Writeline OSInfo + vbCrLf
  OutFile.Writeline BoardInfo  + vbCrLf
  OutFile.Writeline CPUInfo  + vbCrLf
  OutFile.Writeline MemoryInfo  + vbCrLf
  OutFile.Writeline DiskInfo  + vbCrLf
  OutFile.Writeline VideoInfo  + vbCrLf
  OutFile.Writeline NetWorkInfo + vbCrLf
阅读(1349) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~