码迷,mamicode.com
首页 > 移动开发 > 详细

VB.NET 取BIOS信息

时间:2015-07-25 16:56:46      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:bios   wmi   vb.net   

如何获取电脑BIOS 序列号、制造商、版本号及名称等信息?我记是可以使用

WINAPI与ASM获取BIOS硬件信息的 但是我不知道何做,才疏学浅没有办法

那么便选择我使用过的吧,利用微软提供 给我们的WMI接口 BIOS方面在WMI对外

开放的接口为Win32_BIOS 下图是代码运行后的一个效果、

技术分享

MSDN: Win32_BIOS class

The  Win32_BIOS WMI class represents the attributes of the computer system‘s basic input/output services (BIOS) that are installed on a computer.

The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties. Properties are listed in alphabetic order, not MOF order.

Syntax:

[Provider("CIMWin32")]class Win32_BIOS : CIM_BIOSElement
{
  uint16   BiosCharacteristics[];
  string   BIOSVersion[];
  string   BuildNumber;
  string   Caption;
  string   CodeSet;
  string   CurrentLanguage;
  string   Description;
  uint8    EmbeddedControllerMajorVersion;
  uint8    EmbeddedControllerMinorVersion;
  string   IdentificationCode;
  uint16   InstallableLanguages;
  datetime InstallDate;
  string   LanguageEdition;
  String   ListOfLanguages[];
  string   Manufacturer;
  string   Name;
  string   OtherTargetOS;
  boolean  PrimaryBIOS;
  datetime ReleaseDate;
  string   SerialNumber;
  string   SMBIOSBIOSVersion;
  uint16   SMBIOSMajorVersion;
  uint16   SMBIOSMinorVersion;
  boolean  SMBIOSPresent;
  string   SoftwareElementID;
  uint16   SoftwareElementState;
  string   Status;
  uint8    SystemBiosMajorVersion;
  uint8    SystemBiosMinorVersion;
  uint16   TargetOperatingSystem;
  string   Version;
};

上面很多与BIOS相关联的属性,具体的成员释义请参照MSDN、

    Sub Main()
        Dim objWMIService = GetObject("winmgmts:\\.\root\cimv2")
        Dim objBiosCollection = objWMIService.ExecQuery("select * from Win32_BIOS")
        If (objBiosCollection.Count <= 0) Then
            Console.WriteLine("您的电脑没有BIOS,那么您是如何开机的呢?")
        Else
            Console.WriteLine("您的电脑拥有的BIOS:")
            Dim nNoOfBiosHardware As Integer = vbNull
            For Each objBiosHardware In objBiosCollection
                Dim strBiosHardwareInfo = "序号: " & nNoOfBiosHardware & vbNewLine
                strBiosHardwareInfo &= "名称: " & GetNameOfBiosHardware(objBiosHardware) & vbNewLine
                strBiosHardwareInfo &= "制造商: " & GetManufacturerOfBiosHardware(objBiosHardware) & vbNewLine
                strBiosHardwareInfo &= "序列号: " & GetSerialNumberOfBiosHardware(objBiosHardware) & vbNewLine
                strBiosHardwareInfo &= "版本号: " & GetVersionOfBiosHardware(objBiosHardware) & vbNewLine
                Console.WriteLine(strBiosHardwareInfo)
            Next
            Console.ReadKey(False)
        End If
    End Sub

上面的代码我为了不使用.NET包装后WMI对象类 利用VB是后期绑定的特性

直接调用GetObject函数创建WMI服务,在通过WQL查询 在创建WMI服务时

动态绑定路径字符串有一定要求 详情参阅:Constructing a Moniker String

The moniker string format is similar to that of a standard WMI object path. For more information, see  WMI Object Path Requirements.

A moniker has the following parts:

  • The prefix WinMgmts: (mandatory)
  • A security settings component (optional)
  • A WMI object path component (optional)

You cannot specify a password in a WMI moniker string. If you must change the password (strPassword parameter) or the type of authentication (strAuthority parameter) when connecting to WMI, then call  SWbemLocator.ConnectServer. Be aware that you can only specify the password and authority in connections to remote computers. Attempting to set these in a script that is running on the local computer results in a error.

The following moniker specifies the  SWbemServices object that represents the namespace root\default, with impersonation on and the wbemPrivilegeDebug (SeDebugPrivilege) privilege enabled, and the wbemPrivilegeSecurity (SeSecurityPrivilege) privilege disabled.


"winmgmts:{impersonationLevel=impersonate," _
    & "(debug,!security)}!root\default"

取BIOS序列号

    Function GetSerialNumberOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.SerialNumber
        Else
            Return Nothing
        End If
    End Function

取BIOS制造商

    Function GetManufacturerOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.Manufacturer
        Else
            Return Nothing
        End If
    End Function

取BIOS版本号

    Function GetVersionOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.Version
        Else
            Return Nothing
        End If
    End Function

取BIOS名称

    Function GetNameOfBiosHardware(ByVal objBiosHardware) As String
        If (Marshal.IsComObject(objBiosHardware)) Then
            Return objBiosHardware.Name
        Else
            Return Nothing
        End If
    End Function

上面的代码似乎都没有太大的意义、只有一项存在意义 那么则是BIOS序列

号我们做软件授权时,可能会需要CPU、 BIOS、DISK的一个有效序列号

不扯了、需要代码可以到 http://pan.baidu.com/s/1hqB3zSw 百度网盘下载

 

 

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

VB.NET 取BIOS信息

标签:bios   wmi   vb.net   

原文地址:http://blog.csdn.net/u012395622/article/details/47056723

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!