VB.NET 取BIOS信息

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

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

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

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

MSDN: Win32_BIOS class

The Win32_BIOSWMI classrepresents 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,seeWMI 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 callSWbemLocator.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百度网盘下载

相关文章

Format[$] ( expr [ , fmt ] ) format 返回变体型 format$ 强...
VB6或者ASP 格式化时间为 MM/dd/yyyy 格式,竟然没有好的办...
在项目中添加如下代码:新建窗口来显示异常信息。 Namespace...
转了这一篇文章,原来一直想用C#做k3的插件开发,vb没有C#用...
Sub 分列() ‘以空格为分隔符,连续空格只算1个。对所选...
  窗体代码 1 Private Sub Text1_OLEDragDrop(Data As Dat...