您现在的位置: 天下网吧 >> 网吧天地 >> 天下码农 >> 架构师 >> 正文

vb中使用wmi获取系统硬件和软件有关信息

在VB中使用WMI获取系统硬件和软件有关信息

简介:

WMI是英文Windows Management
Instrumentation的简写,它的功能主要是:访问本地主机的一些信息和服务,可以管理远程计算机(当然你必须要拥有足够的权限),比如:重启,关机,关闭进程,创建进程等。

实例如下:

'用WMI,先工程-引用 Microsoft WMI Scripting V1.1 Library

获取显卡/声卡/内存/操作系统的信息

声卡信息

Private Sub wmiSoundDeviceInfo()

Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject

Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_SoundDevice")
On Local Error Resume Next

For Each obj In wmiObjSet
MsgBox obj.ProductName
Next
End Sub


显卡信息

Private Sub wmiVideoControllerInfo()

Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject

Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_VideoController")

On Local Error Resume Next

For Each obj In wmiObjSet
MsgBox obj.VideoProcessor
Next
End Sub

内存信息

Private Sub wmiPhysicalMemoryInfo()

Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject

Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}"). _
InstancesOf("Win32_PhysicalMemory")

On Local Error Resume Next

For Each objItem In wmiObjSet
Debug.Print "BankLabel: " & objItem.BankLabel
Debug.Print "Capacity: " & objItem.Capacity
Debug.Print "Caption: " & objItem.Caption
Debug.Print "CreationClassName: " & objItem.CreationClassName
Debug.Print "DataWidth: " & objItem.DataWidth
Debug.Print "Description: " & objItem.Description
Debug.Print "DeviceLocator: " & objItem.DeviceLocator
Debug.Print "FormFactor: " & objItem.FormFactor
Debug.Print "HotSwappable: " & objItem.HotSwappable
Debug.Print "InstallDate: " & objItem.InstallDate
Debug.Print "InterleaveDataDepth: " & objItem.InterleaveDataDepth
Debug.Print "InterleavePosition: " & objItem.InterleavePosition
Debug.Print "Manufacturer: " & objItem.Manufacturer
Debug.Print "MemoryType: " & objItem.MemoryType
Debug.Print "Model: " & objItem.Model
Debug.Print "Name: " & objItem.name
Debug.Print "OtherIdentifyingInfo: " & objItem.OtherIdentifyingInfo
Debug.Print "PartNumber: " & objItem.PartNumber
Debug.Print "PositionInRow: " & objItem.PositionInRow
Debug.Print "PoweredOn: " & objItem.PoweredOn
Debug.Print "Removable: " & objItem.Removable
Debug.Print "Replaceable: " & objItem.Replaceable
Debug.Print "SerialNumber: " & objItem.SerialNumber
Debug.Print "SKU: " & objItem.SKU
Debug.Print "Speed: " & objItem.Speed
Debug.Print "Status: " & objItem.Status
Debug.Print "Tag: " & objItem.Tag
Debug.Print "TotalWidth: " & objItem.TotalWidth
Debug.Print "TypeDetail: " & objItem.TypeDetail
Debug.Print "Version: " & objItem.Version
Next
End Sub

操作系统信息

Private Sub Command1_Click()
Dim wmiObjSet As SWbemObjectSet
Dim obj As SWbemObject
Dim msg As String
Dim dtb As String
Dim d As String
Dim t As String
Dim bias As Long
On Local Error Resume Next
Set wmiObjSet = GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_OperatingSystem")
For Each obj In wmiObjSet
MsgBox "你当前使用的系统是 " & obj.Caption
Next
End Sub

说明:

大家可能会发现一个规律,实际上WMI对信息的提取都是使用了WIN32_类库名这样的规律,下列表格就是微软的操作系统各种硬件类的描述

其它WMI管理的类的信息在

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/accessing_hardware_and_software_through_wmi.asp

可以找到,其中也还有部分示例代码

简单Win_32类表Win32 Classes

Microsoft® Windows® classes give you the means to manipulate a variety of objects. The following table identifies the categories of Windows classes.

CategoryDescriptionComputer system hardwareClasses that represent hardware related objects.Operating systemClasses that represent operating system related objects.Installed applicationsClasses that represent software related objects.WMI service managementClasses used to manage WMI.Performance counters

Classes that represent formatted and raw performance data.

欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛 https://bbs.txwb.com

关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩

本文来源:我要购书网 作者:我要购书网

声明
声明:本站所发表的文章、评论及图片仅代表作者本人观点,与本站立场无关。若文章侵犯了您的相关权益,请及时与我们联系,我们会及时处理,感谢您对本站的支持!联系邮箱:support@txwb.com,系统开号,技术支持,服务联系QQ:1175525021本站所有有注明来源为天下网吧或天下网吧论坛的原创作品,各位转载时请注明来源链接!
天下网吧 网吧天下
  • 本周热门
  • 本月热门
  • 阅读排行