获得硬件信息的有关文章

原创 2004年07月25日 19:35:00

要验证用户是否合法,一个方法是获取用户的硬件信息。如果同一个SerialNumber有多个不同硬件用户使用,一般就可以kill掉这个SerialNumber了。

VB.NET中得到计算机硬件信息
作者:孟宪会 出自:【孟宪会之精彩世界】 发布日期:2003年7月25日 5点30分58秒

本文汇集了在.NET中得到计算机硬件信息的一些功能。

得到显示器分辨率 Dim X As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width Dim Y As Short = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height MsgBox("您的显示器分辨率是:" & X & " X " & Y) 得到特殊文件夹的路径 '"Desktop"桌面文件夹路径 MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)) '"Favorites"收藏夹路径 MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.Favorites)) '"Application Data"路径 MsgBox(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)) '通用写法 'Dim SPEC As String = Environment.GetFolderPath(Environment.SpecialFolder.XXXXXXX) 'XXXXXXX是特殊文件夹的名字 得到操作系统版本信息 MsgBox(Environment.OSVersion.ToString) 得到当前登录的用户名 MsgBox(Environment.UserName) 得到当前应用程序的路径 MsgBox(Environment.CurrentDirectory) 打开和关闭CD-ROM '先新建模块 Module mciAPIModule Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _ (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _ ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer End Module '打开CD-ROM Dim lRet As Long lRet = mciSendString("set cdAudio door open", 0&, 0, 0) '关闭CD-ROM Dim lRet As Long lRet = mciSendString("set cdAudio door Closed", 0&, 0, 0) '更多请参见 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/multimed/mmcmdstr_8eyc.asp 得到计算机IP和计算机全名 Dim MYIP As System.Net.IPHostEntry = System.Net.Dns.GetHostByName(System.Net.Dns.GetHostName) MsgBox("您的IP地址:" & (MYIP.AddressList.GetValue(0).ToString)) MsgBox("您的计算机全名:" & (MYIP.HostName.ToString)) 使用win32_operatingSystem (wmi Class)得到计算机信息 '添加ListBox在Form1_Load事件里,并引用system.Managment Dim opSearch As New ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") Dim opInfo As ManagementObject For Each opInfo In opSearch.Get() ListBox1.Items.Add("Name: " & opInfo("name").ToString()) ListBox1.Items.Add("Version: " & opInfo("version").ToString()) ListBox1.Items.Add("Manufacturer: " & opInfo("manufacturer").ToString()) ListBox1.Items.Add("Computer name: " & opInfo("csname").ToString()) ListBox1.Items.Add("Windows Directory: " & opInfo("windowsdirectory").ToString()) Next 列出计算机安装的全部字体,并添加到ListBox '新建Form并添加ListBox和Button Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fntCollection As InstalledFontCollection = New InstalledFontCollection() Dim fntFamily() As FontFamily fntFamily = fntCollection.Families ListBox1.Items.Clear() Dim i As Integer = 0 For i = 0 To fntFamily.Length - 1 ListBox1.Items.Add(fntFamily(i).Name) Next End Sub 使用Win32_Processor列出处理器的信息 Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows 窗体设计器生成的代码 " Public Sub New() MyBase.New() '该调用是 Windows 窗体设计器所必需的。 InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub '窗体重写 dispose 以清理组件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Windows 窗体设计器所必需的 Private components As System.ComponentModel.IContainer '注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Friend WithEvents Button1 As System.Windows.Forms.Button Private Sub InitializeComponent() Me.ListBox1 = New System.Windows.Forms.ListBox Me.Button1 = New System.Windows.Forms.Button Me.SuspendLayout() ' 'ListBox1 ' Me.ListBox1.Location = New System.Drawing.Point(8, 8) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(280, 186) Me.ListBox1.TabIndex = 0 ' 'Button1 ' Me.Button1.Location = New System.Drawing.Point(56, 208) Me.Button1.Name = "Button1" Me.Button1.Size = New System.Drawing.Size(168, 32) Me.Button1.TabIndex = 1 Me.Button1.Text = "装载计算机处理器信息" ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(296, 254) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button1, Me.ListBox1}) Me.Text = "计算机处理器信息" Me.ResumeLayout(False) End Sub #End Region Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles Button1.Click Dim ProcQuery As New SelectQuery("Win32_Processor") Dim ProcSearch As New ManagementObjectSearcher(ProcQuery) Dim ProcInfo As ManagementObject For Each ProcInfo In ProcSearch.Get() Call processorfamily(ProcInfo("Family").ToString) ListBox1.Items.Add("Description: " & ProcInfo("Description").ToString()) ListBox1.Items.Add("caption: " & ProcInfo("caption").ToString()) ListBox1.Items.Add("Architecture: " & ProcInfo("Architecture").ToString()) Call processortype(ProcInfo("ProcessorType").ToString()) Call CpuStat(ProcInfo("CpuStatus").ToString) ListBox1.Items.Add("MaxClockSpeed: " & ProcInfo("MaxClockSpeed").ToString() & "MHZ") ListBox1.Items.Add("L2CacheSpeed: " & ProcInfo("L2CacheSpeed").ToString() & "MHZ") ListBox1.Items.Add("ExtClock: " & ProcInfo("L2CacheSpeed").ToString() & "MHZ") ListBox1.Items.Add("ProcessorId: " & ProcInfo("ProcessorId").ToString()) ListBox1.Items.Add("AddressWidth: " & ProcInfo("AddressWidth").ToString() & "Bits") ListBox1.Items.Add("DataWidth: " & ProcInfo("DataWidth").ToString() & "Bits") ListBox1.Items.Add("Version: " & ProcInfo("Version").ToString()) ListBox1.Items.Add("ExtClock: " & ProcInfo("ExtClock").ToString() & "MHZ") Next End Sub Function processorfamily(ByVal procssfam) Dim processtype Select Case procssfam Case 1 processtype = "Other" Case 2 processtype = "Unknown " Case 3 processtype = "8086 " Case 4 processtype = "80286 " Case 5 processtype = "80386 " Case 6 processtype = "80486 " Case 7 processtype = "8087 " Case 8 processtype = "80287 " Case 9 processtype = "80387 " Case 10 processtype = "80487 " Case 11 processtype = "Pentium brand " Case 12 processtype = "Pentium Pro " Case 13 processtype = "Pentium II " Case 14 processtype = "Pentium processor with MMX technology " Case 15 processtype = "Celeron " Case 16 processtype = "Pentium II Xeon " Case 17 processtype = "Pentium III " Case 18 processtype = "M1 Family " Case 19 processtype = "M2 Family " Case 24 processtype = "K5 Family " Case 25 processtype = "K6 Family " Case 26 processtype = "K6-2 " Case 27 processtype = "K6-3 " Case 28 processtype = "AMD Athlon Processor Family " Case 29 processtype = "AMD Duron Processor " Case 30 processtype = "AMD2900 Family " Case 31 processtype = "K6-2+ " Case 32 processtype = "Power PC Family " Case 33 processtype = "Power PC 601 " Case 34 processtype = "Power PC 603 " Case 35 processtype = "Power PC 603+ " Case 36 processtype = "Power PC 604 " Case 37 processtype = "Power PC 620 " Case 38 processtype = "Power PC X704 " Case 39 processtype = "Power PC 750 " Case 48 processtype = "Alpha Family " Case 49 processtype = "Alpha 21064 " Case 50 processtype = "Alpha 21066 " Case 51 processtype = "Alpha 21164 " Case 52 processtype = "Alpha 21164PC " Case 53 processtype = "Alpha 21164a " Case 54 processtype = "Alpha 21264 " Case 55 processtype = "Alpha 21364 " Case 64 processtype = "MIPS Family " Case 65 processtype = "MIPS R4000 " Case 66 processtype = "MIPS R4200 " Case 67 processtype = "MIPS R4400 " Case 68 processtype = "MIPS R4600 " Case 69 processtype = "MIPS R10000 " Case 80 processtype = "SPARC Family " Case 81 processtype = "SuperSPARC " Case 82 processtype = "microSPARC II " Case 83 processtype = "microSPARC IIep " Case 84 processtype = "UltraSPARC " Case 85 processtype = "UltraSPARC II " Case 86 processtype = "UltraSPARC IIi " Case 87 processtype = "UltraSPARC III " Case 88 processtype = "UltraSPARC IIIi " Case 96 processtype = "68040 " Case 97 processtype = "68xxx Family " Case 98 processtype = "68000 " Case 99 processtype = "68010 " Case 100 processtype = "68020 " Case 101 processtype = "68030 " Case 112 processtype = "Hobbit Family " Case 120 processtype = "Crusoe TM5000 Family " Case 121 processtype = "Crusoe TM3000 Family " Case 128 processtype = "Weitek " Case 130 processtype = "Itanium Processor " Case 144 processtype = "PA-RISC Family " Case 145 processtype = "PA-RISC 8500 " Case 146 processtype = "PA-RISC 8000 " Case 147 processtype = "PA-RISC 7300LC " Case 148 processtype = "PA-RISC 7200 " Case 149 processtype = "PA-RISC 7100LC " Case 150 processtype = "PA-RISC 7100 " Case 160 processtype = "V30 Family " Case 176 processtype = "Pentium III Xeon " Case 177 processtype = "Pentium III Processor with Intel SpeedStep Technology " Case 178 processtype = "Pentium 4 " Case 179 processtype = "Intel Xeon " Case 180 processtype = "AS400 Family " Case 181 processtype = "Intel Xeon processor MP " Case 182 processtype = "AMD AthlonXP Family " Case 183 processtype = "AMD AthlonMP Family " Case 184 processtype = "Intel Itanium 2 " Case 185 processtype = "AMD Opteron Family " Case 190 processtype = "K7 " Case 200 processtype = "IBM390 Family " Case 201 processtype = "G4 " Case 202 processtype = "G5 " Case 250 processtype = "i860 " Case 251 processtype = "i960 " Case 260 processtype = "SH-3 " Case 261 processtype = "SH-4 " Case 280 processtype = "ARM " Case 281 processtype = "StrongARM " Case 300 processtype = "6x86 " Case 301 processtype = "MediaGX " Case 302 processtype = "MII " Case 320 processtype = "WinChip " Case 350 processtype = "DSP " Case 500 processtype = "Video Processor " End Select ListBox1.Items.Add("Family: " & processtype) End Function Function CpuStat(ByVal CpuStNUM) Dim stat Select Case CpuStNUM Case 0 stat = "Unknown " Case 1 stat = "CPU Enabled " Case 2 stat = "CPU Disabled by User via BIOS Setup " Case 3 stat = "CPU Disabled By BIOS (POST Error) " Case 4 stat = "CPU is Idle " Case 5 stat = "Reserved " Case 6 stat = "Reserved " Case 7 stat = "Other " End Select ListBox1.Items.Add("CpuStatus: " & stat) End Function Function processortype(ByVal proctypenum) Dim proctype Select Case proctypenum Case 1 proctype = "Other " Case 2 proctype = "Unknown " Case 3 proctype = "Central Processor " Case 4 proctype = "Math Processor " Case 5 proctype = "DSP Processor " Case 6 proctype = "Video Processor " End Select ListBox1.Items.Add("Processor Type: " & proctype) End Function End Class 得到CD-ROM信息 Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows 窗体设计器生成的代码 " Public Sub New() MyBase.New() '该调用是 Windows 窗体设计器所必需的。 InitializeComponent() '在 InitializeComponent() 调用之后添加任何初始化 End Sub '窗体重写 dispose 以清理组件列表。 Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub 'Windows 窗体设计器所必需的 '注意: 以下过程是 Windows 窗体设计器所必需的 '可以使用 Windows 窗体设计器修改此过程。 '不要使用代码编辑器修改它。 Private components As System.ComponentModel.IContainer Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Private Sub InitializeComponent() Me.ListBox1 = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'ListBox1 ' Me.ListBox1.Location = New System.Drawing.Point(24, 16) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(416, 173) Me.ListBox1.TabIndex = 0 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(456, 206) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _ Handles MyBase.Load On Error Resume Next Dim SoundDeviceQuery As New SelectQuery("Win32_CDROMDrive") Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery) Dim SoundDeviceInfo As ManagementObject For Each SoundDeviceInfo In SoundDeviceSearch.Get() Dim SizeInMBs As Long = (Val(SoundDeviceInfo("Size").ToString())) SizeInMBs = Int((SizeInMBs / (1024 * 1024))) ListBox1.Items.Add("CD-Rom Description: " & SoundDeviceInfo("caption").ToString()) ListBox1.Items.Add("CD-Rom Manufacturer: " & SoundDeviceInfo("Manufacturer").ToString()) ListBox1.Items.Add("CD-Rom Drive: " & SoundDeviceInfo("drive").ToString()) ListBox1.Items.Add("CD-Rom Media Loaded: " & SoundDeviceInfo("MediaLoaded").ToString()) ListBox1.Items.Add("CD-Rom Media Type: " & SoundDeviceInfo("MediaType").ToString()) ListBox1.Items.Add("CD-Rom Volume Name: " & SoundDeviceInfo("VolumeName").ToString()) ListBox1.Items.Add("CD-Rom Size: " & SizeInMBs & " MBytes") ListBox1.Items.Add("CD-Rom Status: " & SoundDeviceInfo("Status").ToString()) ListBox1.Items.Add("CD-Rom MaxMediaSize: " & SoundDeviceInfo("MaxMediaSize").ToString()) ListBox1.Items.Add("CD-Rom Id: " & SoundDeviceInfo("Id").ToString()) ListBox1.Items.Add("CD-Rom TransferRate: "+Int(SoundDeviceInfo("TransferRate").ToString())+" KBs/秒") Next End Sub End Class 得到硬盘信息 Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() InitializeComponent() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private components As System.ComponentModel.IContainer Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Private Sub InitializeComponent() Me.ListBox1 = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'ListBox1 ' Me.ListBox1.Location = New System.Drawing.Point(8, 8) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(272, 212) Me.ListBox1.TabIndex = 0 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 238) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load On Error Resume Next Dim HDDDeviceQuery As New SelectQuery("Win32_DiskDrive") Dim HDDDeviceSearch As New ManagementObjectSearcher(HDDDeviceQuery) Dim HDDDeviceInfo As ManagementObject For Each HDDDeviceInfo In HDDDeviceSearch.Get() ListBox1.Items.Add("HDD Description: " & HDDDeviceInfo("caption").ToString()) ListBox1.Items.Add("HDD BytesPerSector: " & HDDDeviceInfo("BytesPerSector").ToString()) ListBox1.Items.Add("HDD CompressionMethod: " & HDDDeviceInfo("CompressionMethod").ToString()) ListBox1.Items.Add("HDD Index: " & HDDDeviceInfo("Index").ToString()) ListBox1.Items.Add("HDD InstallDate: " & HDDDeviceInfo("InstallDate").ToString()) ListBox1.Items.Add("HDD Manufacturer: " & HDDDeviceInfo("Manufacturer").ToString()) ListBox1.Items.Add("HDD Partitions: " & HDDDeviceInfo("Partitions").ToString()) ListBox1.Items.Add("HDD Size: " & Int(Val(HDDDeviceInfo("Size").ToString()) / 2 ^ 30) & " GBytes") ListBox1.Items.Add("HDD TotalCylinders: " & HDDDeviceInfo("TotalCylinders").ToString()) ListBox1.Items.Add("HDD TotalSectors: " & HDDDeviceInfo("TotalSectors").ToString()) ListBox1.Items.Add("HDD TracksPerCylinder: " & HDDDeviceInfo("TracksPerCylinder").ToString()) ListBox1.Items.Add("HDD TotalHeads: " & HDDDeviceInfo("TotalHeads").ToString()) ListBox1.Items.Add("HDD TotalTracks: " & HDDDeviceInfo("TotalTracks").ToString()) ListBox1.Items.Add("HDD SectorsPerTrack: " & HDDDeviceInfo("SectorsPerTrack").ToString()) ListBox1.Items.Add("HDD SCSILogicalUnit: " & HDDDeviceInfo("SCSILogicalUnit").ToString()) Next End Sub End Class 得到声卡信息 Imports System.Management Public Class Form1 Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() InitializeComponent() End Sub Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Private components As System.ComponentModel.IContainer Friend WithEvents ListBox1 As System.Windows.Forms.ListBox Private Sub InitializeComponent() Me.ListBox1 = New System.Windows.Forms.ListBox Me.SuspendLayout() ' 'ListBox1 ' Me.ListBox1.Location = New System.Drawing.Point(8, 8) Me.ListBox1.Name = "ListBox1" Me.ListBox1.Size = New System.Drawing.Size(272, 212) Me.ListBox1.TabIndex = 0 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.ClientSize = New System.Drawing.Size(292, 238) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.ListBox1}) Me.Name = "Form1" Me.Text = "Form1" Me.ResumeLayout(False) End Sub #End Region Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim SoundDeviceQuery As New SelectQuery("Win32_SoundDevice") Dim SoundDeviceSearch As New ManagementObjectSearcher(SoundDeviceQuery) Dim SoundDeviceInfo As ManagementObject For Each SoundDeviceInfo In SoundDeviceSearch.Get() ListBox1.Items.Add("Sound Device Description: " & SoundDeviceInfo("Caption").ToString()) ListBox1.Items.Add("Sound Device Status: " & SoundDeviceInfo("status").ToString()) ListBox1.Items.Add("Sound Device Manufacturer: " & SoundDeviceInfo("Manufacturer").ToString()) Next End Sub End Class

从csdn以硬件为关键词搜索找到如下资源:
http://dev.csdn.net/develop/article/24/24025.shtm

使用WMI获得硬盘的信息     acewang [原作]
关键字   WMI HardDisk
出处  

首先,什么是WMI?
   WMI(Windows管理架构:Windows Management Instrumentation)是Microsoft基于Web的企业管理(WBEM)和 Desktop Management Task Force(DMTF)工业标准的实现. 就是一种基于标准的系统管理的开发接口,这组接口用来控制管理计算机. 它提供了一种简单的方法来管理和控制系统资源.
    如果你想深入了解他,可以参考Micorosft Platform SDK . 在这我们只是通过它实现一个简单的功能,  得到我们系统中硬盘的相关信息.
    我们需要使用.net Framwork里面System.Management名字空间下提供的类来实现.

using System;
using
System.Management;
using
System.Collections;
using System.Collections.Specialized;
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

namespace ACE_Console
{
       class ACE_Console
       {
              [STAThread]
              static void <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />Main
(string[] args)
              {
                     StringCollection propNames = new StringCollection();
                     ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
                     PropertyDataCollection  props = driveClass.Properties;
                     foreach (PropertyData driveProperty in props) 
                     {
                            propNames.Add(driveProperty.Name);
                     }

 

                     int idx = 0;
                    ManagementObjectCollection drives = driveClass.GetInstances();
                     foreach (ManagementObject drv in drives) 
                    
                            Console.WriteLine(" Drive({0}) Properties ", idx+1);
                            foreach (string strProp in propNames)
                            {
                                   Console.WriteLine("Property: {0}, Value: {1}", strProp, drv[strProp]);
                            }
                     }
              }
       }
}    

.net Framework SDK自带的帮助里有获得逻辑硬盘大小的代码:

[C#]

using System;

using System.Management;

           

 // This example demonstrates getting information about a class using the ManagementClass object

class Sample_ManagementClass

{

       public static int Main(string[] args)

       {

              ManagementClass diskClass = new ManagementClass("Win32_LogicalDisk");

              diskClass.Get();

              Console.WriteLine("Logical Disk class has " + diskClass.Properties.Count + " properties");

              return 0;

       }

}                                


[vb]
Imports
System

Imports System.Management

       

// This example demonstrates getting information about a class using the ManagementClass

Class Sample_ManagementClass

Overloads Public Shared Function Main(args() As String) As Integer

Dim diskClass As New ManagementClass("Win32_LogicalDisk")

diskClass.Get()

Console.WriteLine(("Logical Disk class has " & diskClass.Properties.Count.ToString() & " properties"))

Return 0

End Function

End Class

 

 

VB中使用WMI获取系统硬件和软件有关信息     SoHo_Andy [原作]
关键字   WMI 系统 信息 硬件 软件
出处  

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

http://dev.csdn.net/develop/article/23/23371.shtm

简介:

      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.

Category Description
Computer system hardware Classes that represent hardware related objects.
Operating system Classes that represent operating system related objects.
Installed applications Classes that represent software related objects.
WMI service management Classes used to manage WMI.
Performance counters

Classes that represent formatted and raw performance data.

 

 

硬件类

Computer System Hardware Classes

he Cooling Devices subcategory groups classes that represent instrumentable fans, temperature probes, and refrigeration devices.

Class Description
Win32_Fan Represents the properties of a fan device in the computer system.
Win32_HeatPipe Represents the properties of a heat pipe cooling device.
Win32_Refrigeration Represents the properties of a refrigeration device.
Win32_TemperatureProbe Represents the properties of a temperature sensor (electronic thermometer).

Input Device Classes

The Input Devices subcategory groups classes that represent keyboards and pointing devices.

Class Description
Win32_Keyboard Represents a keyboard installed on a Windows system.
Win32_PointingDevice Represents an input device used to point to and select regions on the display of a Windows computer system.

Mass Storage Classes

Classes in the Mass Storage subcategory represent storage devices such as hard disk drives, CD-ROM drives, and tape drives.

Class Description
Win32_AutochkSetting Represents the settings for the autocheck operation of a disk.
Win32_CDROMDrive Represents a CD-ROM drive on a Windows computer system.
Win32_DiskDrive Represents a physical disk drive as seen by a computer running the Windows operating system.
Win32_FloppyDrive Manages the capabilities of a floppy disk drive.
Win32_PhysicalMedia Represents any type of documentation or storage medium.
Win32_TapeDrive Represents a tape drive on a Windows computer.

Motherboard, Controller, and Port Classes

The Motherboard, Controllers, and Ports subcategory groups classes that represent system devices. Examples include system memory, cache memory, and controllers.

Class Description
Win32_1394Controller Represents the capabilities and management of a 1394 controller.
Win32_1394ControllerDevice Relates the high-speed serial bus (IEEE 1394 Firewire) Controller and the CIM_LogicalDevice instance connected to it.
Win32_AllocatedResource Relates a logical device to a system resource.
Win32_AssociatedProcessorMemory Relates a processor and its cache memory.
Win32_BaseBoard Represents a baseboard (also known as a motherboard or system board).
Win32_BIOS Represents the attributes of the computer system's basic input/output services (BIOS) that are installed on the computer.
Win32_Bus Represents a physical bus as seen by a Windows operating system.
Win32_CacheMemory Represents cache memory (internal and external) on a computer system.
Win32_ControllerHasHub Represents the hubs downstream from the universal serial bus (USB) controller.
Win32_DeviceBus Relates a system bus and a logical device using the bus.
Win32_DeviceMemoryAddress Represents a device memory address on a Windows system.
Win32_DeviceSettings Relates a logical device and a setting that can be applied to it.
Win32_DMAChannel Represents a direct memory access (DMA) channel on a Windows computer system.
Win32_FloppyController Represents the capabilities and management capacity of a floppy disk drive controller.
Win32_IDEController Represents the capabilities of an Integrated Drive Electronics (IDE) controller device.
Win32_IDEControllerDevice Association class that relates an IDE controller and the logical device.
Win32_InfraredDevice Represents the capabilities and management of an infrared device.
Win32_IRQResource Represents an interrupt request line (IRQ) number on a Windows computer system.
Win32_MemoryArray Represents the properties of the computer system memory array and mapped addresses.
Win32_MemoryArrayLocation Relates a logical memory array and the physical memory array upon which it exists.
Win32_MemoryDevice Represents the properties of a computer system's memory device along with it's associated mapped addresses.
Win32_MemoryDeviceArray Relates a memory device and the memory array in which it resides.
Win32_MemoryDeviceLocation Association class that relates a memory device and the physical memory on which it exists.
Win32_MotherboardDevice Represents a device that contains the central components of the Windows computer system.
Win32_OnBoardDevice Represents common adapter devices built into the motherboard (system board).
Win32_ParallelPort Represents the properties of a parallel port on a Windows computer system.
Win32_PCMCIAController Manages the capabilities of a Personal Computer Memory Card Interface Adapter (PCMCIA) controller device.
Win32_PhysicalMemory Represents a physical memory device located on a computer as available to the operating system.
Win32_PhysicalMemoryArray Represents details about the computer system's physical memory.
Win32_PhysicalMemoryLocation Relates an array of physical memory and its physical memory.
Win32_PNPAllocatedResource Represents an association between logical devices and system resources.
Win32_PNPDevice Relates a device (known to Configuration Manager as a PNPEntity), and the function it performs.
Win32_PNPEntity Represents the properties of a Plug and Play device.
Win32_PortConnector Represents physical connection ports, such as DB-25 pin male, Centronics, and PS/2.
Win32_PortResource Represents an I/O port on a Windows computer system.
Win32_Processor Represents a device capable of interpreting a sequence of machine instructions on a Windows computer system.
Win32_SCSIController Represents a small computer system interface (SCSI) controller on a Windows system.
Win32_SCSIControllerDevice Relates a SCSI controller and the logical device (disk drive) connected to it.
Win32_SerialPort Represents a serial port on a Windows system.
Win32_SerialPortConfiguration Represents the settings for data transmission on a Windows serial port.
Win32_SerialPortSetting Relates a serial port and its configuration settings.
Win32_SMBIOSMemory Represents the capabilities and management of memory-related logical devices.
Win32_SoundDevice Represents the properties of a sound device on a Windows computer system.
Win32_SystemBIOS Relates a computer system (including data such as startup properties, time zones, boot configurations, or administrative passwords) and a system BIOS (services, languages, system management properties).
Win32_SystemDriverPNPEntity Relates a Plug and Play device on the Windows computer system and the driver that supports the Plug and Play device.
Win32_SystemEnclosure Represents the properties associated with a physical system enclosure.
Win32_SystemMemoryResource Represents a system memory resource on a Windows system.
Win32_SystemSlot Represents physical connection points including ports, motherboard slots and peripherals, and proprietary connections points.
Win32_USBController Manages the capabilities of a universal serial bus (USB) controller.
Win32_USBControllerDevice Relates a USB controller and the CIM_LogicalDevice instances connected to it.
Win32_USBHub Represents the management characteristics of a USB hub.

Networking Device Classes

The Networking Devices subcategory groups classes that represent the network interface controller, its configurations, and its settings.

Class Description
Win32_NetworkAdapter Represents a network adapter on a Windows system.
Win32_NetworkAdapterConfiguration Represents the attributes and behaviors of a network adapter. The class is not guaranteed to be supported after the ratification of the Distributed Management Task Force (DMTF) CIM network specification.
Win32_NetworkAdapterSetting Relates a network adapter and its configuration settings.

Power Classes

The Power subcategory groups classes that represent power supplies, batteries, and events related to these devices.

Class Description
Win32_AssociatedBattery Relates a logical device and the battery it is using.
Win32_Battery Represents a battery connected to the computer system.
Win32_CurrentProbe Represents the properties of a current monitoring sensor (ammeter).
Win32_PortableBattery Represents the properties of a portable battery, such as one used for a notebook computer.
Win32_PowerManagementEvent Represents power management events resulting from power state changes.
Win32_UninterruptiblePowerSupply Represents the capabilities and management capacity of an uninterruptible power supply (UPS).
Win32_VoltageProbe Represents the properties of a voltage sensor (electronic voltmeter).

Printing Classes

The Printing subcategory groups classes that represent printers, printer configurations, and print jobs.

Class Description
Win32_DriverForDevice Relates a printer to a printer driver.
Win32_Printer Represents a device connected to a Windows computer system that is capable of reproducing a visual image on a medium.
Win32_PrinterConfiguration Defines the configuration for a printer device.
Win32_PrinterController Relates a printer and the local device to which the printer is connected.
Win32_PrinterDriver Represents the drivers for a Win32_Printer instance.
Win32_PrinterDriverDll Relates a local printer and its driver file (not the driver itself).
Win32_PrinterSetting Relates a printer and its configuration settings.
Win32_PrintJob Represents a print job generated by a Windows application.
Win32_TCPIPPrinterPort Represents a TCP/IP service access point.

Telephony Classes

The Telephony subcategory groups classes that represent "plain old telephone" modem devices and their associated serial connections.

Class Description
Win32_POTSModem Represents the services and characteristics of a Plain Old Telephone Service (POTS) modem on a Windows system.
Win32_POTSModemToSerialPort Relates a modem and the serial port the modem uses.

Video and Monitor Classes

The Video and Monitors subcategory groups classes that represent monitors, video cards, and their associated settings.

Class Description
Win32_DesktopMonitor Represents the type of monitor or display device attached to the computer system.
Win32_DisplayConfiguration Represents configuration information for the display device on a Windows system. This class is obsolete. In place of this class, use the properties in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution classes.
Win32_DisplayControllerConfiguration Represents the video adapter configuration information of a Windows system. This class is obsolete. In place of this class, use the properties in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution classes.
Win32_VideoConfiguration This class has been eliminated from Windows XP and later; attempts to use it will generate a fatal error. In place of this class, use the properties contained in the Win32_VideoController, Win32_DesktopMonitor, and CIM_VideoControllerResolution classes.
Win32_VideoController Represents the capabilities and management capacity of the video controller on a Windows computer system.
Win32_VideoSettings Relates a video controller and video settings that can be applied to it.

 

而每一个类都有对应的数据结构如

显卡

class Win32_VideoController : CIM_PCVideoController { uint16 []; string ; string ; uint32 ; uint16 ; string []; string ; uint32 ; uint32 ; boolean ; string ; uint32 ; uint32 ; uint64 ; uint32 ; uint32 ; uint32 ; uint16 ; uint32 ; string ; string ; uint32 ; uint32 ; datetime ; string ; boolean ; string ; uint32 ; uint32 ; string ; string ; datetime ; string ; uint32 ; uint32 ; uint32 ; uint32 ; uint32 ; boolean ; string ; uint16 ; uint32 ; string ; uint16 []; boolean ; uint16 ; uint32 ; uint32 ; string ; uint16 ; string ; string ; uint32 ; datetime ; uint16 ; uint16 ; uint16 ; string ; string ; };

声卡等

class Win32_SoundDevice : CIM_LogicalDevice
{
  uint16 Availability;
  string Caption;
  uint32 ConfigManagerErrorCode;
  boolean ConfigManagerUserConfig;
  string CreationClassName;
  string Description;
  string DeviceID;
  uint16 DMABufferSize;
  boolean ErrorCleared;
  string ErrorDescription;
  datetime InstallDate;
  uint32 LastErrorCode;
  string Manufacturer;
  uint32 MPU401Address;
  string Name;
  string PNPDeviceID;
  uint16 PowerManagementCapabilities[];
  boolean PowerManagementSupported;
  string ProductName;
  string Status;
  uint16 StatusInfo;
  string SystemCreationClassName;
  string SystemName;
};

class Win32_PrintJob : CIM_Job
{
  string Caption;
  string DataType;
  string Description;
  string Document;
  string DriverName;
  datetime ElapsedTime;
  string HostPrintQueue;
  datetime InstallDate;
  uint32 JobId;
  string JobStatus;
  string Name;
  string Notify;
  string Owner;
  uint32 PagesPrinted;
  string Parameters;
  string PrintProcessor;
  uint32 Priority;
  uint32 Size;
  datetime StartTime;
  string Status;
  uint32 StatusMask;
  datetime TimeSubmitted;
  uint32 TotalPages;
  datetime UntilTime;
};

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

可以获得打印任务列表等信息

 

对于VB来讲获得系统硬件和软件信息大都使用API,现在使用WMI可以快速的实现我们的目标.如获取驱动器/显卡/共享信息等等都会变得方便和有效

 

 

 

2018跟着小虎玩着去软考--锦绣文章(分享信息系统项目管理师论文应试技巧)

首先是学会如何点评学员论文,其次分享论文考试的应试技巧(如论文的摘要、正文、总结),接着是探秘信息系统项目管理师论文出题,揭开考试神秘面纱,最后真枪实弹对项目管理九大领域各个领域论文,各个突破,包括热点论文。 小虎老师的QQ软考群: 139240819 结交考友、结伴同行、经验分享、答疑解惑.... (一次课程付费,直至通过考试,真题免费更新)
  • 2017年04月29日 09:47

Appium —— DesiredCapabilitites

Appium 服务关键字 关键字 描述 实例 automationName 你想使用的自动化测试引擎 Appium (默认) 或 Selendroid ...
  • qq_24297963
  • qq_24297963
  • 2016-09-08 14:06:41
  • 64

android 获取设备硬件信息

/** * * */ package net.sunniwell.app; import android.app.Activity; import and...
  • jingwen3699
  • jingwen3699
  • 2012-07-18 21:39:52
  • 10519

转载 有关DDR的文章

組長:謝宗恩 組員:陳健民       曾雨祥       黃宏志 指導老師:林明璋   日期:2009年4月8日                 一、何謂DDR3 ...
  • jackle_zheng
  • jackle_zheng
  • 2012-04-02 17:44:50
  • 811

C++ 获取硬件信息

  • 2014年03月24日 15:01
  • 1.11MB
  • 下载

C#获取当前主机硬件信息

获取计算机的相关硬件信息,CPU序列号、MAC地址、内外网ip、主机序列号等。...
  • scimence
  • scimence
  • 2015-04-01 20:03:16
  • 7844

获取电脑硬件信息

1.操作系统UUID 不同的用户使用不同的工具取到的可能取出来的不一样,但是仔细观察,他们的字符串是一样的,可能是大小端转换的问题 工具:HWiNFO32.EXE和everestultimate...
  • xiaoxiaoyu85
  • xiaoxiaoyu85
  • 2015-09-01 21:12:55
  • 986

得到linux中硬件信息的shell

, 主板信息.查看主板的序列号--------------------------------------------------#使用命令dmidecode | grep -i serial num...
  • super_ufo
  • super_ufo
  • 2009-06-09 17:12:00
  • 758

获取计算机硬件信息的VB.NET代码范例

获取计算机硬件信息的VB.NET代码范例     得到显示器分辨率    本文相关代码如下: Dim X As Short = Sy...
  • wl58796351
  • wl58796351
  • 2011-08-19 09:15:39
  • 1909

一篇有关《JAVA的未来和发展》文章 C

 2.4 Java将回归桌面应用在2005年的JavaOne大会上,Sun公司透露Java将进军传统的桌面应用。并立志在这方面挤垮微软公司。然而在过去的几年里,每个Java开发爱好者都会认为java在...
  • wurenhai
  • wurenhai
  • 2007-12-23 20:51:00
  • 938
收藏助手
不良信息举报
您举报文章:获得硬件信息的有关文章
举报原因:
原因补充:

(最多只允许输入30个字)