标题: 分享一段获得系统信息的脚本 [打印本页] 作者: ziheng198688 时间: 2009-6-5 15:22 标题: 分享一段获得系统信息的脚本 Public Function GetComputerInfor()
Dim Win
Set Win = GetObject("WinMgmts:")
Dim CompInfor
Set CompInfor = Win.InstancesOf("Win32_ComputerSystem")
Dim OsInfor
Set OsInfor = Win.InstancesOf("Win32_OperatingSystem")
For Each objComputer In CompInfor
ModelNo = objComputer.Model
Next
For Each objComputer In OsInfor
OSName = objComputer.Caption
ServicePack = objComputer.ServicePackMajorVersion
Next
Set Win = Nothing
End Function作者: 南拳王 时间: 2009-7-3 11:05
最好能添加一些详细的注视,这样的话可能对人会更有帮助!作者: lvguobin 时间: 2009-7-3 11:43
不过总算有分享意识,我来帮他注释一下
Public Function GetComputerInfor()
Dim Win
Set Win = GetObject("WinMgmts:")
Dim CompInfor
Set CompInfor = Win.InstancesOf("Win32_ComputerSystem")
Dim OsInfor
Set OsInfor = Win.InstancesOf("Win32_OperatingSystem")
For Each objComputer In CompInfor
ModelNo = objComputer.Model '获取机器型号
Next
For Each objComputer In OsInfor
OSName = objComputer.Caption '操作系统
ServicePack = objComputer.ServicePackMajorVersion '操作系统版本
Next
Set Win = Nothing
End Function
获取硬件信息:
Set wmi=GetObject("winmgmts:\\")
Set board=wmi.instancesof("win32_baseboard")
For Each b In board
msg="主板:"&b.Manufacturer&vbTab&b.product&vbTab&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)
Set cpus=wmi.instancesof("win32_processor")
msg=msg&"CPU 特征:"+Chr(13)
For Each cpu In cpus
msg=msg+cpu.deviceid&vbTab&cpu.name&Chr(13) _
&vbtab&cpu.SocketDesignation&vbtab&cpu.CurrentClockSpeed&"MHz"&vbtab&cpu.l2cachesize&"Kb_L2"&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)
Set mem=wmi.instancesof("win32_physicalmemory")
msg=msg&"内存容量:"+Chr(13)
For Each m In mem
msg=msg&m.tag&space(10)&m.capacity&+Chr(13)
Next
Set mem=wmi.instancesof("win32_computersystem")
For Each m In mem
msg=msg&"内存总容量:"&Round((m.totalphysicalmemory/1024^2),2)&"M"+Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)
Set display=wmi.instancesof("Win32_videocontroller")
msg=msg&"显示系统:"+Chr(13)
For Each video In display
msg=msg&video.deviceid&vbTab&video.name&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)
Set disks=wmi.instancesof("win32_diskdrive")
msg=msg&"硬盘容量:"+Chr(13)
For Each d In disks
If int(d.size/(1024^3))=0 Then
n=Round(d.size/(1024^2),2)&"M"
Else
n=Round(d.size/(1024^3),2)&"G"
End If
msg=msg+d.deviceid&" 空间为: "&n&Chr(13)
Next
msg=msg&Chr(13)&"---"+Chr(13)