VBS

On Error Resume Next
temp = 0
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

'用一個文本來記錄硬件信息
Set WshNetWork = WScript.CreateObject("WSCript.Network")
computername = WshNetwork.ComputerName
Set fso=CreateObject("scripting.filesystemobject")
tempfilter="C:\"&computername&".txt"
tempfilter="\\test\"&computername&".txt"

'這裡是硬件信息記錄的存放位置,可以使網絡共享路徑(需要有寫入的權限)
Set tempfile = fso.createtextfile(tempfilter)
strComputer="."
Set objWMIService = GetObject("winmgmts:\\"&strComputer&"\root\cimv2")
'Set objWMIService = GetObject("winmgmts:"&"{impersonationLevel=impersonate}!\\" &strComputer&"\root\cimv2")

'主板
Set board = objWMIService.ExecQuery("select * from win32_baseboard")
 For Each item In board
 board2="MainBoard:"&item.Product 
 board3="MainBoard Manufacturer: "&item.Manufacturer
 board4="MainBoard SerialNumber: "&item.SerialNumber
 Next

'CPU
Set cpu = objWMIService.ExecQuery("select * from win32_processor")
 For Each item In cpu
 cpu2 = "CPU:"&item.Name
 Next

'Memory
Set colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
 For Each objitem In colItems
  a=objitem.capacity/1048576
  temp = temp+objitem.capacity  
  n=n+1
  Next
  memory = temp/1048576
  If n=1 Then 
   memory2= "Memory:"&n&"pieces "&a&"M"
  Else
   memory2="Memory:"&n&"pieces "&a&"M"&",Total: "&memory&"M"
  End If

'硬盤
Set disk = objWMIService.ExecQuery("select * from win32_diskdrive")
 For Each item In disk
  disk2 = "HardDisk:"&item.Model
  Next

'get disk
' Drive Type 3  Local Disk
' Drive Type 4  Net Disk
Set LogicDisk = objWMIService.ExecQuery("select * from Win32_Logicaldisk WHERE DriveType=3")
 For Each logicd In LogicDisk
  LogicDisk2=LogicDisk2&logicd.DeviceID&"  "&Round(logicd.FreeSpace/1048576)&"M " '&vbCrlf
 Next  

'顯卡
Set video = objWMIService.ExecQuery("select * from win32_videocontroller",,48)
 For Each item In video
 video2 = "VideoCard:"&item.Description
 Next


'On Error Resume Next
'Time
'Set colLocalTime = objWMIService.ExceQuery("select * from Win32_LocalTime")
Set colLocalTimes = objWMIService.ExecQuery("Select * from Win32_LocalTime")
 For Each objLocalTime in colLocalTimes
 LocalTime = LocalTime&"Date: " &  objLocalTime.Year & "/" & objLocalTime.Month&"/" &objLocalTime.Day '&vbCrlf
 Next


'On Error Resume Next
'網卡物理地址
Set colNicConfigs = objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
For Each objNicConfig In colNicConfigs

Set objNic = objWMIService.Get("Win32_NetworkAdapter.DeviceID=" & objNicConfig.Index)
strMacAddress = "MAC: "&objNic.MACAddress

If Not IsNull(objNicConfig.IPAddress) Then
 For i=LBound(objNicConfig.IPAddress) To UBound(objNicConfig.IPAddress)
  strIPAddress = strIPAddress&objNicConfig.IPAddress(i)
 Next
End If

Next

'On Error Resume Next
'網卡
'Set colItems = objWMIService.ExceQuery("select *from Win32_NetworkAdapter",,48)
 'For Each ojbitem In colItems
  'If (len(objitem.NetConnectionID,4)>1) Then
  'x = x+1
  'MsgBox(x)
   'lanname = lanname&":"&objitem.Name
   'lanname = lanname&vbCrlf
  'End If
 ''Next
 'lan2 = "NetCard:"&lanname

Set osinfo = GetObject("winmgmts:").InstancesOf("Win32_OperatingSystem")
For Each os In osinfo
 osinformation =osinformation&"Version: "&os.Caption&" "&os.Version & VBCRLF
 osinformation =osinformation&"Build: "&os.BuildNumber&" "&os.BuildType & VBCRLF
 osinformation =osinformation&"CSD Version: "&os.CSDVersion & VBCRLF
 osinformation =osinformation&"Serial Number: "&os.SerialNumber & VBCRLF


 osinformation =osinformation&"Manufacturer: "&os.Manufacturer& VBCRLF
 osinformation =osinformation&"Free Physical Memory: "&os.FreePhysicalMemory& VBCRLF
 osinformation =osinformation&"Free Space in Paging Files: "&os.FreeSpaceInPagingFiles& VBCRLF
 osinformation =osinformation&"Size Stored in Paging Files: "&os.SizeStoredInPagingFiles& VBCRLF 
 osinformation =osinformation&"Free Virtual Memory: "&os.FreeVirtualMemory& VBCRLF

 osinformation =osinformation&"Total Virtual Memory Size: "&os.TotalVirtualMemorySize& VBCRLF
 osinformation =osinformation&"Total Visible Memory Size: "&os.TotalVisibleMemorySize& VBCRLF

 osinformation =osinformation&"Current Time Zone: "&os.CurrentTimeZone& VBCRLF
 osinformation =osinformation&"Install Date: "&os.InstallDate& VBCRLF
 osinformation =osinformation&"Last Bootup Time: "&os.LastBootUpTime & VBCRLF
 osinformation =osinformation&"Local Date & Time: "&os.LocalDateTime & VBCRLF

 osinformation =osinformation&"Foreground App Boost: "&os.ForegroundApplicationBoost & VBCRLF
 osinformation =osinformation&"Maximum #Processes: "&os.MaxNumberOfProcesses & VBCRLF
 osinformation =osinformation&"Maximum Memory Size for Processes: "&os.MaxProcessMemorySize & VBCRLF
 osinformation =osinformation&"Processes Number: "&os.NumberOfProcesses & VBCRLF

 osinformation =osinformation&"Users Number: "&os.NumberOfUsers & VBCRLF
 osinformation =osinformation&"Registered User: "&os.RegisteredUser & VBCRLF

 osinformation =osinformation&"Code Set: "&os.CodeSet & VBCRLF
 osinformation =osinformation&"Country Code: "&os.CountryCode & VBCRLF
 osinformation =osinformation&"Locale: "&os.Locale & VBCRLF

 osinformation =osinformation&"Boot Device: "&os.BootDevice & VBCRLF
 osinformation =osinformation&"Name: "&os.CSName & VBCRLF
 osinformation =osinformation&"Status: "&os.Status & VBCRLF
 osinformation =osinformation&"System Device: "&os.SystemDevice & VBCRLF
 osinformation =osinformation&"System Directory: "&os.SystemDirectory & VBCRLF
 osinformation =osinformation&"Windows Directory: "&os.WindowsDirectory
 Next

tempfile.writeline(board2)
tempfile.writeline(board3)
tempfile.writeline(board4)
tempfile.writeline(cpu2)
tempfile.writeline(memory2)
tempfile.writeline(disk2)
tempfile.writeline(LogicDisk2)
tempfile.writeline(video2)
tempfile.writeline(LocalTime)
tempfile.writeline("IPAddress: "&strIPAddress)
tempfile.writeline(strMacAddress)
'tempfile.writeline(lan2) 
tempfile.writeline(osinformation)
tempfile.close


Set fx = fso.opentextfile(tempfilter,8,true)
Set objReg = GetObject("winmgmts://" & strComputer &"/root/default:StdRegProv")
Const HKLM =&H80000002
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "InstallDate"
strEntry3 = "VersionMajor"
strEntry4 = "VersionMinor"
strEntry5 = "EstimatedSize"

objReg.EnumKey HKLM, strKey, arrSubkeys
For Each strSubkey In arrSubkeys
  intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey,strEntry1a, strValue1)
  If intRet1 <> 0 Then
    objReg.GetStringValue HKLM, strKey & strSubkey,strEntry1b, strValue1
  End If
  If strValue1 <> "" Then
     fx.writeline  VbCrLf & "Display Name: " & strValue1
  End If
   objReg.GetStringValue HKLM, strKey & strSubkey,strEntry2, strValue2
  If strValue2 <> "" Then
    fx.writeline "Install Date: " & strValue2
  End If
  objReg.GetDWORDValue HKLM, strKey & strSubkey,strEntry3, intValue3
  objReg.GetDWORDValue HKLM, strKey & strSubkey,strEntry4, intValue4
  If intValue3 <> "" Then
      fx.writeline "Version: " & intValue3 & "." & intValue4
  End If
  objReg.GetDWORDValue HKLM, strKey & strSubkey,strEntry5, intValue5
  If intValue5 <> "" Then
     fx.writeline "Estimated Size: " & Round(intValue5/1024, 3) & " mega bytes"
  End If
Next
'MsgBox(software)

posted on 2007-03-09 09:10  KenL  阅读(423)  评论(0)    收藏  举报

导航