爱子日志

用vbs统计公司电脑配置

首先我们先确定下我们的目的,我们需要得到的内容有,显示器、cpu、内存、主板、显卡、硬盘、ip等等,将这些数据搜集上来,写在txt文件里,最后发送到我们指定的共享文件里(这里的必须是完全共享)下面想具体代码:

ON ERROR RESUME Next
  
MsgBox"本操作为采集公司办公设备,请大家积极配合," & Chr(13) & Chr(10) & "认真填写你所在部门和姓名," & Chr(13) & Chr(10) & "有问题请联系网络管理员,电话,谢谢合作",vbYes, "博纳集团计算机盘点系统"
  
Temp = 0
 Set WSHNetwork = WScript.CreateObject("WScript.Network")
 ComputerName = WSHNetwork.ComputerName
  
While Dept=""
 Dept=InputBox("请输入你所在的部门:","提示")
 Wend
  
While Name=""
 Name=InputBox("请输入你名字:","提示")
 Wend
 While Showq=""
 Showq=InputBox("请输入你电脑显示器的型号:" & Chr(13) & Chr(10) & "例:方正17纯平,方正17液晶 等","提示")
 Wend
  
TempFiles = "\\192.168.8.20\com\info\" & ComputerName &".txt"
 Set FSO = CreateObject("Scripting.FileSystemObject")
 Set TempFile = FSO.CreateTextFile(TempFiles)
 strComputer = "."
 Set objWMIService = Getobject("winmgmts:\\" & strComputer & "\root\cimv2")
  
Set CPU = objWMIService.ExecQuery("Select * From Win32_Processor")
 For Each Item In CPU
 CPU2 = "CPU:" & Item.Name
 Next
  
Set Board = objWMIService.ExecQuery("Select * From Win32_BaseBoard")
 For Each Item In Board
 Board2 = "主板: " & Item.Product
 Next
  
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 = "内存: " & N & "条" & A & "M"
 Else
 Memory2 = "内存: " & N & "条" & A & "M" &" 总计" & Memory & "M"
 End If
  
Set Video = objWMIService.ExecQuery("Select * From Win32_VideoController",,48)
 For Each Item In Video
 Video2 = "显卡: " & Item.Description
 Next
  
Set Disk = objWMIService.ExecQuery("Select * From Win32_DiskDrive")
 For Each Item In Disk
 Disk2 = Disk2 & Item.Model & " "
 Next
 Disk3 = "硬盘: " & Trim(Disk2)
  
Set Network = objWMIService.ExecQuery("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = true")
 For Each Item In Network
 Lan = "网卡: " & Item.Description
 Next
  
Set IPConfigSet = objWMIService.ExecQuery("Select IPAddress from Win32_NetworkAdapterConfiguration where IPEnabled=true")
 For Each IPConfig in IPConfigSet
 If Not IsNull(IPConfig.IPAddress) Then
 For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress)
 IP = IP & IPConfig.IPAddress(i) & " "
 Next
 End If
 Next
 IP = "IP: " & Trim(IP)
  
Set mc=GetObject("Winmgmts:").InstancesOf("Win32_NetworkAdapterConfiguration")
 For Each Item In mc
 If Item.IPEnabled=True Then
 Mac=Mac & Item.MacAddress & " "
 End If
 Next
 Mac = "MAC: " & Trim(Mac)
  
Name = "姓名: "&Name
 Dept = "部门: "&Dept
 Showq = "显示器: "&Showq
 TempFile.WriteLine(Dept)
 TempFile.WriteLine(Name)
 TempFIle.WriteLine(Showq)
 TempFile.WriteLine(CPU2)
 TempFile.WriteLine(Board2)
 TempFile.WriteLine(Memory2)
 TempFile.WriteLine(Video2)
 TempFile.WriteLine(Disk3)
 TempFile.WriteLine(Lan)
 TempFile.WriteLine(IP)
 TempFile.WriteLine(mac)
 TempFile.Close
 MsgBox "信息传送完毕,谢谢合作",vbYes,"北京博纳集团公司"

将上面的代码写到txt文件里,然后改名为vbs,然后发给客户机器运行下,就可以了,我们上面提到要得到的内容就全部发到你的共享文件里了,注意请更改里面的共享地址!


点击下载

转载自:http://hi.baidu.com/ainaol/blog/item/e46d820e7ebad1ec36d122d0.html

聚划算